starcrusher n00b
Joined: 28 Jul 2004 Posts: 20 Location: Campinas / SP - Brazil
|
Posted: Tue Mar 29, 2005 10:12 pm Post subject: tcl/expect error "spawn id exp0 not open" |
|
|
Hello all,
I have to build a routine that automatically logins to a remote service, send a command, and retrieve its answer. I'm planning this routine will be one node of a pipe stream, so I'm trying to read the command from stdin and export the answer to stdout. Please consider the following expect script (which i named "std_exp"):
Code: |
#!/usr/bin/expect -f
stty raw -echo
remove_nulls 0
# Read a non-ASCII command from stdin.
# It doesn't have a fixed size nor terminator, so let's look for EOF.
set command ""
set timeout 10
expect_user {
timeout { send_error "ERR: timeout.\n" ; exit 1 }
-re "(.+)" { append command $expect_out(1,string) ; exp_continue }
eof
}
# Here I would spawn a connection to a remote service,
# deal with the login procedures, send the command and catch the answer.
set answer "Duh?"
# Now print the answer to stdout.
send_user -- "$answer"
exit 0
|
There is no way of knowing the end of the command but parsing it (it's a variable-size packet with a checksum at the end), but this is a job for the remote service and I'm trying to keep things simple.
This is what happens when I run std_exp as part of a pipe in my Gentoo system:
Code: | user@host expect $ echo "qwerty88" | ./std_exp | cat
send: spawn id exp0 not open
while executing
"send_user -- "$answer""
(file "./std_exp" line 21) |
Apparently the EOF on stdin also closes stdout of the expect process, so I can't write to stdout anymore . "puts" instead of "send_user" also hangs; "send_error" works, but uses stderr (which is heavily used by the real script for logging purposes, so redirection is out of question).
In expect, is there a way to keep stdout open even if stdin receives EOF?
If not, is there another way implement this funcionality?
Thanks in advance,
starcrusher _________________ People can be divided in 10 groups:
Those that do and those that don't understand binary arithmetic. |
|