XXXX@XXXXX.COM (TingChong) writes: That's a very vague term. The OS has no such label for processes, so you'll have to elaborate on exactly what you mean by "hung". Don
XXXX@XXXXX.COM (TingChong) writes: That's a very vague term. The OS has no such label for processes, so you'll have to elaborate on exactly what you mean by "hung". Don
"alive" is not well defined either. But if you "expect eof", most expect scripts consider the process dead. Technically, that's not true - the process can enter the zombie state and then when you do a wait on the process, it finally disappears from the system. Bottom line: choose the definition which best suits your need. Don XXXX@XXXXX.COM (TingChong) writes:
The standard output and input of spawned process are channels connect to expect and send commands in the main Expect program. main program spawned program expect ... puts ... send ... gets stdin ... you can display hourglass in the spawned program. Chang
Active : all states before the function is exited (e.g. ready or suspended or delayed states).
If that's really your definition, you can use "exp_wait". However, it's generally sufficient (and simpler) to wait for an eof. As I recall your earlier code fragment did exactly that already - so I'm wondering if I missed reading something between the lines? Don XXXX@XXXXX.COM (TingChong) writes:
1.Expect: spawn telnet doesn't work if I spawn from process which is forked
nikolao wrote: > Hi, > > I have a problem which happens on my ubuntu machine, and on my freebsd > 7.2 works perfectly well. In my script I fork some processes and those > processes are trying to connect to some network nodes and do some > things. Here is part of the script code: > > set timeout 20 > > proc start_client {} { > global maxclient > global targets > set n [llength $targets] > if {$n < $maxclient} { > set maxclient $n > } > foreach client $targets > if {[fork] == 0} { > disconnect > log_file logs/$client.log > send_log "$client started at [timestamp]" > client_body $client > log_file > } > } > #parent waits that children finish, here I use after command > #but in original I do something else > after 1000000 > } > > proc client_body {ip} { > global spawn_id > set id [spawn telnet $ip] > set login_status [login_node "username" "password"] > if { $login_status == -1 } { > puts "$ip: invalid username or password" > return -1 > } elseif { $login_status == 1 } { > execute_command_on_remote_node > } > exit > } > > proc login_user {user password} { > global timeout > > expect { > timeout { return 0 } > "Username:" { send "$user\r" } > } > expect { > timeout { return 0 } > "Password:" { send "$password\r" } > } > expect { > "Username or password invalid!" { return -1 } > "Fail" { return -1 } > ">" { } > } > return 1 > } > > > As I can trace execution of script, it enters login_user procedure, > and then login_user returns 0 from the first expect statement, altough > I can telnet to targets. What is really strange, is that, if I do not > fork processes and spawn from parent, my script works. And what is > more strange, my forked script works perfectly on my freebsd 7.2 > machine. 1. Is there a reason to fork like mad? ( you could use [exp_background -i $spawn_id] instead and have all [spawn]s in one expect process. 2. You expect "Username:" and "Password:" most implementations send "..name: " and "...word: " notice the trailing space. Not expecting this space will lead to subtle errors: i.e. premature sending of the reply. 3. what is in the input buffer? ( change the {return 0} to {expect -re .* ; parray expect_out ; return 0 } uwe
2.Expect: spawn telnet doesn't work if I spawn from process which is forked
Hi, I have a problem which happens on my ubuntu machine, and on my freebsd 7.2 works perfectly well. In my script I fork some processes and those processes are trying to connect to some network nodes and do some things. Here is part of the script code: set timeout 20 proc start_client {} { global maxclient global targets set n [llength $targets] if {$n < $maxclient} { set maxclient $n } foreach client $targets if {[fork] == 0} { disconnect log_file logs/$client.log send_log "$client started at [timestamp]" client_body $client log_file } } #parent waits that children finish, here I use after command #but in original I do something else after 1000000 } proc client_body {ip} { global spawn_id set id [spawn telnet $ip] set login_status [login_node "username" "password"] if { $login_status == -1 } { puts "$ip: invalid username or password" return -1 } elseif { $login_status == 1 } { execute_command_on_remote_node } exit } proc login_user {user password} { global timeout expect { timeout { return 0 } "Username:" { send "$user\r" } } expect { timeout { return 0 } "Password:" { send "$password\r" } } expect { "Username or password invalid!" { return -1 } "Fail" { return -1 } ">" { } } return 1 } As I can trace execution of script, it enters login_user procedure, and then login_user returns 0 from the first expect statement, altough I can telnet to targets. What is really strange, is that, if I do not fork processes and spawn from parent, my script works. And what is more strange, my forked script works perfectly on my freebsd 7.2 machine.
3.Expect on windows - matching output of a process spawned "outside" expect
Karthick wrote: > On May 24, 2:49 am, David Gravereaux < XXXX@XXXXX.COM > wrote: >> Karthick wrote: >> >> ... >> >>> I do not understand how I can retrieve the value of the hello.exe >>> process. >> You can't. There is a bug in the process management of the debugger >> routine that ignores ConsoleAPI calls made by other processes. In this >> case, the other process is the one you're interested in, rather than the >> one you spawned. >> >> To fix, spawn the process you are interested in as you showed works. > > Hi David, > > I was going through the bug list in SourceForge to understand what you > said better.. but couldn't find an entry that seems to fit (I could > have missed it though). > > Can you let me know whether, is this an issue only with windows, or > with linux version of expect as well? > > Thanks for your help > > Regards, > Karthick Just windows. I'm sure it would be easy to fix, though, given the proper dev environment. The guts are found in the ConsoleDebugger C++ class for the threadHandlerProc member function, I think. When a debug event for a process creation happens, it stores the "procinfo" to a linkedlist and uses it as an association for any other events that will take place after it. The bug is in there, because it apparently isn't finding the "procinfo" or some other logic error. A perfect example would be using Expect to spawn cvs.exe which will launch ssh.exe. You most definitely want to catch the output of ssh as well as cvs so you can login correctly. The source for E4W is available from Jeff Hobbs. Just ask him. There was a link he gave about 4 years ago, but can't find it.
4.Expect on windows - matching output of a process spawned "outside" expect
Hi all, I'm trying to learn expect with a few experiments.. I'm on Expect 5.43 + Tcl 8.5.7.0 on windows. I have an hello.exe file compiled from the following C++ source: #include <iostream> int main(int argc, char *argv[]) { char msg[100]; std::cout << "Hello" << std::endl; std::cin >> msg; std::cout << "You said " << msg << std::endl; return 0; } The following expect script works correctly: package require Expect console show set exp::winnt_debug 1 exp_log_user 0 exp_spawn hello expect { "Hello" { puts "Got hello there!" exp_send "Hi\r" exp_continue } "You said Hi" { puts "Worked ok" exp_exit } timeout {puts "Timed out"} } I'm now trying to do the following: a. Start a shell. b. Invoke hello.exe in that shell. c. Match the output of hello.exe. So I modified the script to: package require Expect console show set exp::winnt_debug 1 exp_log_user 0 # Changed the following two lines exp_spawn cmd.exe exp_send "hello\r" expect { "Hello" { puts "Got hello there!" exp_send "Hi\r" exp_continue } "You said Hi" { puts "Worked ok" exp_exit } timeout {puts "Timed out"} } I get time out error now, probably because expect is trying to match the output of cmd.exe, but it needs to instead match the output of hello.exe. I looked up the documentation of the -i flag to expect, but I do not understand how I can retrieve the value of the hello.exe process. Thanks for any help.. Regards, Karthick
5.expect: expect of a spawn process in another routine
Is it ok to have the expect of a spawn process in another routine? e.g. I have the expect in proc spinLock but the process is spawned in proc waitForTape. I have this bug that spawned process is time out but I don't understand why? proc spinLock { } { puts "please wait..." set timeout 10000 expect { timeout { puts "timeout" } eof { puts "process end" } "*Error *" { puts "Received Error while performing a loop" } default { puts "unknown status" } } } proc waitForTape {} { global tapeDevice puts "Please insert a tape and press the <Enter> key to continue." set status 0 while { $status == 0 } { gets stdin line #check tape status set tapeStatus "" if {[catch {spawn /usr/bin/mt -f $tapeDevice status} tapeStatus]} { puts "tapeStatus $tapeStatus" switch -regexp -- $tapeStatus { ".*no tape loaded.*" { puts "Error: no tape is loaded. Please insert a tape and press the <Enter> key to continue" } ".*drive offline.*" { puts "Error: drive offline. Please turn drive online and press the <Enter> key to continue" } default { puts "Error: $tapeStatus. Please fix the problem and press the <Enter> key to continue" } } } else { spinLock set status 1 } } }
6. "telnet localhost" hangs when executing it under expect spawn
Users browsing this forum: No registered users and 7 guest