For Programmers: Free Programming Magazines  


Home > Archive > Tcl > May 2007 > Re: Expect - failed to write error - 6 lines of code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Expect - failed to write error - 6 lines of code
Bezoar

2007-05-29, 7:10 pm

On May 25, 2:18 pm, Skip Gracely <s...@hotmail.com> wrote:
> I'm getting the following error when I run a simple expect script:
>
> "write() failed to write anything - will sleep(1) and retry..."
>
> It happens when the script exits, so it's not really a problem
> aside from having to wait for the sleep(1) to occur. It is more of
> an annoyance in my real script (not shown) because I spawn six
> telnet sessions, so I have to wait six sleep(1) times.
>
> I'm running expect version 5.43.0 on Ubuntu 6.10 on a
> 2.6.17-11-generic linux kernel.
>
> Here's my six line script:
>
> #!/usr/bin/expect
>
> exp_internal 1
>
> set prompt "foo>"
>
> spawn telnet "10.1.1.1"
> expect -re $prompt
>
> send "blah\r"
> expect -re $prompt {}
>
> Any help would be appreciated.
>
> # email address not real - no spam



Are you sending exit to end the session Like:
exp_send -i $spawnid "exit\r"

this may not clean up the children processes you should always wait
for the eof or timeout and
if you timeout then you should kill the children then harvest the
children. Like so
set pid [spawn telnet $ipaddr ]
set sp_id $spawn_id
# do your work here
.....
# now exit
exp_send -i $sp_id "\r" ; # get the prompt again
set timeout 10
expect {
-i $sp_id
-re "$prompt" {
exp_send "exit\r"
exp_continue; # we continue because we want eof or timeout
}
timeout {
exec kill -9 $pid
exp_continue ; # optional with -9 its dead
}
eof {
;
}
}

# now cleanup harvest the child by "waiting" for it otherwise it
becomes a zombie
puts " Exit status : [ exp_wait -i $sp_id ]"
catch { exp_close -i $sp_id }

Note I just typed this in the browser so you may need to adjust...

Carl

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com