Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expect multi-proc interaction

Status
Not open for further replies.

ExpectTheUnexpected

Programmer
Jun 17, 2010
22
US
I am trying to figure out how Expect's interact command works with multiple processes. I have 2 simple scripts below. The objective is to feed output by spawned process id2 to spawned process id1.

#!/usr/bin/expect --

log_user 1
# clear screen
send_user [exec tput reset]

# it appears 'spawn' does not support redirection!
# spawn cat \> abc.txt

spawn vi abc.txt
set id1 $spawn_id

# make id1 ready to accept input from another process
send "i"

spawn /root/Expect-Scripts/test1
set id2 $spawn_id

# Objective: capture output from id2 and save it into abc.txt file opened by id1
interact {
-output $id1
timeout 10 { puts "Timed out!"; return }
eof -i $id2 return
}

send -i $id1 "\033:wq\r"
expect -i $id1 eof {}


test1:

echo Test1
sleep 2
echo Hello I am test1
sleep 2
echo test1 is leaving now...
sleep 2
echo Goodbye!

At the end of run abc.txt should look like this:

Test1
Hello I am test1
test1 is leaving now...
Goodbye!

The interact command can be used to connect processes. Thats what I am trying to do. Above code attempts to take output of the 2nd process and feed it into input of the 1st process but not sure what am I doing wrong. I have tried various variations of it but w/o success. Perhaps, it can't be done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top