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.
Help with exp_send command

Posted by newGirl (newGirl), 23 June 2004
Hello.  I am new to this forum.  I am running Tcl 8.4 with Expect 5.38.  I have a tcl script in which I spawn an application.  After the application is spawned I set the spawn_id to a variable.  I then pass this variable to exp_send to execute a command inside of the application I started.  The problem is that I never see the command that I sent using the exp_send command.  I can execute the "NTestMgr ..." command manually inside of the application.

I have no clue why I do not see the command.  The code looks somewhat like this ...

for { set i 1 } { $i < 13 } { incr i } {
   cd $Dir
   spawn ./program
   set sid_program $spawn_id
   expect -i $sid_program -re "PST>" {
       exp_send -i $sid_program"NTestMgr $suiteDir/[set testSuite$i].ste $gui\r"
       set timeout -1
       expect -i $sid_program "PST>" {
             close -i $sid_program
             wait -i $sid_program
       set timeout 10
   # find the log file
   set pattern "total \[0-9]+(.+)"
   cd $logDir

I know that the first PST> is seen and because I inserted some puts statements before and after the exp_send command.  I see the output from the puts statement before and the output from the puts statement after the exp_send command but I never see the "NTestMgr ........." command sent.  

Also program is a proprietary tool that was developed where I work that was compiled with Tcl 8.3 and Expect 5.40.  Is there maybe a compatibility issue with the Expect version on the machine and the Expect version the program is using?

Any suggesstions would be appreciated.


Posted by admin (Graham Ellis), 24 June 2004
Are you running "program" 12 imes in sucession?  If so, I don't think you need to save spawn_id and then use the -i option all through - you should be fine with simplified code.  The -i option is really only needed where you have a whole list of spawned processes and want to wait on more than one of them at the same time.  

Also .. I think the -re is redundant in the expect that's giving you problems - you're looking for a literal string after all!

I do wonder if the spawn and the PST> prompt is working correctly. You say that you see the effect of put statements before and after the first exp_send ... but not the NTestMgr command - perhaps "program" is failing to echo that back to you as (I think) logging comes back with the received (echo) information rather than what has been sent.   If you play with timeouts, is there an interval between the test puts outputs?

Other thoughts - do you need to add a turn around delay after receiving PST> and before sending in order for the spawned program to be ready to accept input, and is there a space send on the end of the prompt ("PST> ") that you should wait for?

I can't immediatly see anything that I can say "xxxxx" is the cause, but I can suggest that you take out the -i option / take out the -re and debug something shorter and simpler.

Finally, the language that ./program is written in (and the version of that language) should make no difference) - expect uncouples your code and your target application so that you're talking to it just in ASCII sequences.

Hope some of these ideas help / give you something to help you research the problem further.  I sould be very interested to hear what the solution turns out to be - could you post a follow up when you have it sorted, please?

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