Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
tcl/expect error "spawn id exp0 not open"
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
starcrusher
n00b
n00b


Joined: 28 Jul 2004
Posts: 20
Location: Campinas / SP - Brazil

PostPosted: Tue Mar 29, 2005 10:12 pm    Post subject: tcl/expect error "spawn id exp0 not open" Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum