expect "multiple processes" "interact vth console"
Posted by polsoni (soni), 1 April 2004Problem 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
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 2004Problem 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.
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 2004Problem 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.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho