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))
expect "multiple processes" "interact vth console"

Posted by polsoni (soni), 1 April 2004
Problem 1: I made an minimal Expect script to login to a linux box through console port(minicom), but I am not able to figure out how to control the graphics. The graphics are similar to what you get when one uses "Xconfigurator" on linux. Basically controling the up, down, tab, enter key from the keyboard and integrating them into the script.

Problem 2: I spawned two processes one is an "ssh" and other is a "file being opened as a process" on host machine to store the output of the commands initiated on the "ssh" process.
(1) spawn ssh user@IP
(2) spawn -open [open "|cat -u ps" w+]
(3) interact -input $sshPid "*#" "send \"ls -ltr\\n\"" -output $fileIdPid
           -- This gives an error "Cannot interact with self - set spawn_id to a spawned process while executing ..."

expect version: expect-5.38.0
kernel: kernel-2.4.18-3

I am new to expect and would be grateful for any advice/example on how to proceed here.


Posted by admin (Graham Ellis), 3 April 2004
Problem 1.  

Expect is designed for handling awkward command line interfaces and there's no way of saying "press the third button from the left" except in a Tk application.   Best approach might be to direct the graphics to /dev/null and use the keyboard shortcuts.

Problem 2.

When you spawn, a variable called spawn_id is set which can saved (copied) into another variable if you wish, and provides you with a handle through which you can later refer to that particular spawned process.   If you don't save that variable and you do another spawn, the original spawn_id gets overwritten and you can't make specific references to the first process.  

The parameter you give to a -input option in an interact command needs to be a spawn_id that has been saved in this way, otherwise you'll get a message like the one you see.   I guess that you might have done something with your "ps" to get the process id to supply that to intereact.  Sorry - no - that's not how it works; it's actually much simpler  

Posted by polsoni (soni), 5 April 2004
Problem 1: Not familiar with Tk, but will check it out.

Problem 2: If you look at the 3rd command in my list "interact -input $sshPid "*#" "send \"ls -ltr\\n\"" -output $fileIdPid" the "$sshPid" refers to the spawn_id for ssh that I saved in that variable and "$fileIdPid" refers to the spawn_id for file I opened as a spawned process. i.e.
-- set sshPid $spawn_id : after the 1st spawn but before the second spawn.
-- set fileIdPid $spawn_id : after the 2nd spawn.
   I am already doing what you suggested below(I am not using ps for getting the pid's). But the "interact" error stills seems to be coming.

     I have one doubt i.e. after I initiate the first spawn(ssh) when I initiate the second spawn(open file) will it open the file on the remote host or the current host.
      Will check out my doubt as soon as I am able to login into the network I am working in.


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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho