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.
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.

thanks
Soni

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.

Thanks,
Soni



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., 2022: 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