Version 2 of How to access the result of a remote command in Expect

Updated 2002-02-05 20:18:01

[Explain situation.]

[Explain contents of expect_out array.]

To make this code somewhat generic, set the prompt and command here:

   set prompt "date"
   set prompt "% "

Now we can do useful things:

   expect $prompt     ;# wait for prompt
   send "date\r"      ;# send command
   expect $prompt\r\n ;# discard command echo

Finally, match and save the result and discard the next prompt:

   expect -re (.*)\r\n$prompt\r\n"

Now the result is in $expect_out(1,string).

If you want to read more about this, start on page 113 of Exploring Expect.

[Point to references in book.]

[Contact CL if you're in a hurry for content here.]