Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Identify Expect disconnection

Posted by amiry (amiry), 2 August 2005
I'm working with ActiveState Expect for WIndows 5.4

I'm looking for a way to identify disconnection - i.e. communication failure of the spawned process.
e.g. if I make:
exp_spawn telnet $ipaddr $port
and then I use expect several times,
I want to be able to identify a case when the connection with the remote host fails for some reason.

Is there a way to do that with (Windows) expect library?

Thanks in advance!

Posted by admin (Graham Ellis), 2 August 2005
How would you identify a telnet failure in a manually run process?  Perhaps by a lockup, or by an error message when trying to connect, or pehaps by telnet "dropping out".

You have the same tools in expect - you can expect eof and timeout, you can expect error strings, and you can also set the timeout.

If you don't want to have to specify all the options at every expect statement you write, have a look at expect_before and expect_after

Posted by amiry (amiry), 3 August 2005
Thanks for replying, Graham.
I already checked the options you suggest.
'timeout' is not good enough because sometimes the remote process is bussy but communication is still OK (i.e. telnet is still connected).
'eof' and error message - when I killed the remote process there was 'timeout' and not eof or error msg...

I thought there's some error status I can get from expect commands but I didn't find one.
Any suggestion?

Posted by admin (Graham Ellis), 5 August 2005
on 08/03/05 at 15:41:44, amiry wrote:
Thanks for replying, 'timeout' is not good enough because sometimes the remote process is bussy but communication is still OK (i.e. telnet is still connected).

Any suggestion?

Timeout doesn't depend on the whole telnet process timing out - but rather on expect not receiving any input for a certain period. From what you've told us, I think that timeout is perfectly good enough for you.

Posted by amiry (amiry), 7 August 2005
OK, let me put my question this way:
Is there a way to know if the spawned process already exited? i.e. is the same spawned_id still relevant for expect?
(assuming telnet, or other program, exits when it loses connection).

Posted by admin (Graham Ellis), 7 August 2005
That's a different question.   The answer is that you can expect an eof and if you get it, you know the remote process has terminates.  If you get one of the alternatives that you specify in your expect command - either an explicit string, a pattern, or a timeout then you know that your remote process is still connected to you.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho