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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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?
Thanks!

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?
Thanks!


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 www.opentalk.org.uk 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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho