How to store output in a variable while using expect 'send' command

user3153829 picture user3153829 · Jan 2, 2014 · Viewed 33.7k times · Source

Thanks.

But the account and password are needed. So I must send them and then send ovs-vsctl command.

the scripts are something like this:

spawn telnet@ip 

expect -re "*login*" {
       send "root"
}

expect -re "password*" {
       send "****"
}

send "ovs-vsctl *******"

I want to store the output of this command send "ovs-vsctl ****", but many times I got some output of the command "send "password"", how can I get the output of send "ovs-vsctl****". The output of the command send "ovs-vsctl *** are two string and each string occupies one line.

Thanks.

Answer

glenn jackman picture glenn jackman · Jan 2, 2014

Maybe:

log_user 0                   ;# turn off the usual output
spawn telnet@ip 
expect -re "*login*"
send "root\r"
expect -re "password*"
send "****\r"
send "ovs-vsctl *******"
expect eof
puts $expect_out(buffer)     ;# print the results of the command