| |||||||||||
Waiting for the result when running expect script Posted by theaccelerator (theaccelerator), 24 December 2007 I'm running expect script from a C++ program using the popen function.My expect script is using the command: spawn telnet $ipaddress Then it performs login and runs several commands. My problem is that I don't get the results of the script. It seems like I'm getting the control right away and continue with my program before the script has performed the telnet, thus I get and empty result when running the script from my program. How can I wait for the script to end, and receive the results to see if there was a success or some problem has occured. Posted by admin (Graham Ellis), 24 December 2007 Without seeing your program it's hard to know, but one very common problem is that people issues a command through send then fail to wait for the next prompt via expect. The easiest way to describe this is to quote an example - I have seen people all too often connect via FTP, send a get command, and then exit their script. This results in only a partial file being received as the FTP connection is dropped as soon as the expect program exits, and the solution is to expect "ftp>". Posted by theaccelerator (theaccelerator), 25 December 2007 My mistake, it appears like I got the whole interaction as the result, and I thought that the interaction was after I returned.The problem now is how to get only the messages which where send by send_user and not the whole output. Here is a short and simple script, where I would expect to recieve to my C program only the OK. spawn telnet [lindex $argv 0] expect login: send "admin\r" expect Password: send "\r" expect > send "enable\r" expect # send_user "OK" exit This is important since, my script is much more complex and I only want to get as a result if there was some error, or if there was a success. Posted by admin (Graham Ellis), 25 December 2007 Add alog_user 0 at the top This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |