Expect FAQ


Where can I learn about Expect's commands?

ActiveState maintains online copies of documentation at [L1 ].


Is Expect thread-safe?

The answer, by Don Libes recently, was No. [L2 ]


Is there a newer version of Expect that works (and/or works better) for Windows?

Expect for Windows

There is an up-to-date port of Expect for Windows available from ActiveState commercially [L3 ]. Otherwise there is an old port that is based off a hacked version of Tcl 8.0 from Gordon Chaffee.


Why does my script exit immediately without displaying results?

This comes up often when people have scripts like below:

spawn ssh router
send {show config}
send {exit}

If you run this script, it will exit very quickly as though it does nothing.

The reason should be obvious if you imagine the end of the script having an implicit exit:

spawn ssh router
log_user 1
send {show config}
send {exit}
exit

The commands are getting sent to ssh's stdin, but since we never wait for a response there is no guarantee ssh got to read the characters, let alone the remote host! This is much like opening a terminal, typing some commands incredibly quickly and then immediately closing the terminal. You'd be incredibly lucky if this worked.

Normally, the correct answer to this question is to insert after the last send:

expect eof

how to access the result of a remote command in Expect.

How Expect sees function keys

One frequently-asked question is how to send escape characters through Expect.