| |||||||||||
accessing return value in expect Posted by quiknot (quiknot), 28 July 2003 Hi, I have an expect script that rlogin's to another system, and executes a few remote commands on that server. I need to capture the return value of one of the commands given, and then return that value to another script (the one that called the expect script). Here is a rough outline of my expect script:#!/usr/bin/expect -f set prompt "(%|#|\\$|%]) $" catch {set prompt $env(EXPECT_PROMPT)} set timeout 10 set username [lindex $argv 0] set pword [lindex $argv 1] set arg1 [lindex $argv 2] set arg2 [lindex $argv 3] set host "theserver@thehost.com" spawn rlogin -l $username $host expect "assword:*" send "$pword\r" //Connected to remote host expect -re $prompt send "/path/to/the/script $arg1 $arg2 .. need return value of this script expect -re $prompt send "exit\r" //need to return the return value found exit basically it is like this...I call the expect script from php (via exec), it runs on the same server as the webserver, then rlogin's to the other server and runs the scripts...I need to return the return value back to php, can I do this? Thanks! Posted by admin (Graham Ellis), 28 July 2003 Where you say "the return value", do you mean the result that it sends to the screen when you run it manually, or the operating system status value on the remote machine?If you mean the value that it prints out to the screen, you'll find that in the expect array expect_out(buffer) ... after each expect call, this variable contains the text that your application has skipped over while waiting for the correct response. If you're looking for the operating system status variable from the remote computer, I think you best bet would be to execute an extra send - expect cyscle to send an echo command to report on the variable's value, and capture that from expect_out(buffer). Posted by quiknot (quiknot), 29 July 2003 Thanks for the reply Graham. I don't think what you mentioned will work though, since the return value is not output to the screen.However, if an error occurs (what I am testing for), the output of the script would be "Incorrect format or data: NOT checking-in ". Is there a way to test if that output occurs, and if it does, set a variable to 1, and then return that value back to the parent process? (exit $return_variable) Posted by admin (Graham Ellis), 29 July 2003 Quote:
Have a look at the third paragraph of my answer - I think it's answered there - force it to the screen Posted by quiknot (quiknot), 29 July 2003 Ok Graham, I guess I missed that. Do you think you could show me in my code how I could work that in there? I really appreciate all your help!Posted by admin (Graham Ellis), 29 July 2003 err ... I'm away from my normal Tcl / Expect resource this week so I'm answering from memory ... I think you need to addCode:
The "send" may vary depending on which shell you're running on the remote system - check it out manually first. Posted by quiknot (quiknot), 30 July 2003 Excellent...worked great Graham. Thanks for your helpThis 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 |