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.
use return value of a script in the expect script

Posted by pranav_nitt (pranav_nitt), 12 April 2004
Hello all,

I am a beginner for the expect script. The problem i've encountered is as follows..

I  have a expect script which telnets to a remote machine. subsequently i run a perl script from the expect script on that machine.. one of the subroutines in the perl script retunns a value , depending on which i have to proceed with the expect script... How do i access that return value in the expect script

i will provide a outline of the things..
if    return value of sub in perl is 1 no need to proceed further with expect script, i.e close the connection...
  proceed with the expect script....

I will appreciate your help,
Thanks ,


Posted by admin (Graham Ellis), 12 April 2004
Have the Perl script print out the value that it returns rather that having it set a status code (I assume that's what you mean it does).   You can then use the expect command to look for a string that matches each of the possibilities and brances depending on which it receives.

Posted by pranav_nitt (pranav_nitt), 13 April 2004
thanks for the suggestion Graham.. but the problem that arises now is that how do i  check for the output of the perl script , i mean is it possible to access that in my expect script  will it be stored in some variable ( say something of type expect_out...) .

Do let me know,


Posted by admin (Graham Ellis), 13 April 2004
Yes, but you need to have the Perl script print out the value that the subroutine returns.   That value will then appear as part of your expect_out(buffer).  

It might be that you don't want (or can't) modify the output of the Perl program.  If that's the case, then you can have your scripted telnet session run another command once the Perl program has completed to dump out the output file (or do whatever's necessary to get that vital subroutine return values onto the output stream).  The connection between the two systems is purely the telnet session, so all values you want back in your expect program have to be part of that stream

Posted by pranav_nitt (pranav_nitt), 13 April 2004
Hello Graham,

the expect_out(buffer) would store the output until the correct match occurs, rite?? so in this case on encountring the prompt i immediately run the perl script on the remote machine.. so the output of that is not stored in the variable.. how do i get that output in the variable

Please do let me know at the earliest,


Posted by admin (Graham Ellis), 13 April 2004
You print it out in your remote Perl program, use the expect command within your extended Tcl to match something that's towards the end of that printing, and then examine expect_out(string).

Please note that this board is not intended as an emergency support facility - have a look at;action=display;num=1081843563;start=0
where I've written a note about response times.

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