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

Posted by gurudatt (gurudatt), 19 March 2008
Hello,

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
Hi,

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:

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




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