Results 1 to 4 of 4
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.
...
- 12-24-2007 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 2
Waiting for the result when running expect script
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.
- 12-24-2007 #2
Can you post a tiny, complete expect script which duplicates the problem?
Don't forget to alter your user name and password on the remote machine before posting the script.--
Bill
Old age and treachery will overcome youth and skill.
- 12-25-2007 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 2
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.
- 12-25-2007 #4
It's been a while since I've used expect, but here's an example I'm copying straight out of the excellent O'Reilly book Exploring Expect. If there are any errors, they're not my errors; they instead belong to my stubby, clumsy fingers.
Image of sample usage of this script:Code:#!/usr/bin/expect -- log_user 0 regexp (.*)@(.*) $argv ignore user host spawn telenet $host smtp set timeout -1 expect -re "220.*\r\n" send "vrfy $user\r" expect "250" {puts "GOOD"} \ "550" {puts "BAD"}
Hope this helps.Code:% vrfy jobs@next.com GOOD % vrfy jobs@apple.om BAD %
--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote