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.
Forcing a command to be completed

Posted by gurudatt (gurudatt), 19 March 2008

I open a telnet session and send commands to it. one of the commands that i send takes a lot of time to execute, and by this time sometimes the next command also gets executed.
Also the framework that i have developed is such that from my main file i say i have to open a telnet session by creating a object of the class that i have created in another file.

Now to this object i send commands and the function that accepts this has been implemented such that it expects and sends commands.

main.tcl-- main file                
x a telnet                              
x sc command1                    
x sc command2                              

impl.tcl--class that implements
class x {
spawn telnet
sc {command } {
expect "->" {
send -i $id command
Is there anyway that i can force the next command not to be  executed/sent until the previous one?  i.e can i force commad2 to be sent only after command one has finished sending it.

Posted by admin (Graham Ellis), 19 March 2008
set the timeout variable before you execute the first command to long enough to allow it o complete before your send / expect sequence.   That way, expect won't give up and go on to the next command too quickly.

set timeout 50

to allow 50 seconds, for example

Posted by gurudatt (gurudatt), 20 March 2008

It didnt work.

Posted by admin (Graham Ellis), 21 March 2008
Oops - I didn't notice that you weren't waiting - you were sending the first command then carrying right on without even trying to wait for the command to finish so, I agree, timeout won't work.

Try waiting for the telnet session to return with the next prompt:

class x {
spawn telnet
sc {command } {
expect "->" {
send -i $id command
expect "->"

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