Version 3 of spawn

Updated 2005-09-20 21:07:45

[add information about expect's spawn command, pointers to its man page on http://www.tcl.tk/man/ , etc.]

spawn creates a session with a program or remote device that Expect can manage. Spawned sessions can be automated using other Expect commands, such as expect, interact and exp_send.

The man page for spawn is actually part of the Expect man page http://www.tcl.tk/man/expect5.31/expect.1.html .

A very simple example - ping an ip address:

        #!/bin/sh
        # The next line is executed by /bin/sh, but not tcl \
        exec /homes/ashnoc01/noc/rbacon/tcl/ActiveTcl/bin/tclsh8.4 $0 ${1+"$@"}

        package require Expect

        spawn -noecho /usr/local/bin/nping -c 5 $argv
        log_user 0
        expect {
                "\r"        {
                        puts -nonewline "$expect_out(buffer)"
                        exp_continue
                        }
                eof        {
                        puts -nonewline "$expect_out(buffer)"
                        }
                }
        puts "AutoPing finished\n"
        exit

Output:

  > AutoPing 62.188.74.130
  PING 62.188.74.130: 64 data bytes
  EchoReply from 62.188.74.130: len=64 ttl=242 seq=0 time=81.157 ms.
  EchoReply from 62.188.74.130: len=64 ttl=242 seq=1 time=80.768 ms.
  EchoReply from 62.188.74.130: len=64 ttl=242 seq=2 time=80.709 ms.
  EchoReply from 62.188.74.130: len=64 ttl=242 seq=3 time=80.915 ms.
  EchoReply from 62.188.74.130: len=64 ttl=242 seq=4 time=80.940 ms.

  ----62.188.74.130 PING Statistics----
  5 transmitted, 5 received, 0.00% packet loss.
  round-trip (ms) min/avg/max = 80.709/80.898/81.157
                var/sdev/skew/kurt = 0.030/0.174/0.323/1.311
  AutoPing finished














Category Command Category Expect