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

Posted by shafa.fahad (FahaD), 25 September 2006

I found the usage of "Interact" as it allows to pass the control from process to user and back to process when required.

I tried implementing in one of my program, but couldn't get it right. Please add ur advice....

I am trying to read a log file which keeps growing... and pass the control to the user so that they can read till they want and once user presses "q" reading stop and continues the next function...

I went through the Interact example in wellho site and even though it gives some clear picture of interact, I couldn't make use of it since my requirement is slightly different...

expect -re $prompt
Send "tail -1000f /opt/drive1/file1"
<this operation which keeps running needs to be stoped by user intervention>

I appreciate ur patience

Thanks in advance,

Posted by admin (Graham Ellis), 26 September 2006
I'm out of the office at the moment - don't have scope for much more than a quick answer, nor my library to hand.   I'll get back on this in a day or two. If you solve it in the meantime, please post a follow up.



Posted by admin (Graham Ellis), 27 September 2006
OK .. back with you.

I think I might used "expect -i" and expect from both the tail command and also from the keyboard, rather than using interact.  Save the spawn_id before you spawn the tail command  .   I suspect that interact would NOT work for you since you want to have the tail being processed in the background. And in any case what you're looking for is a very simple one key input and not the transparency that interact is designed to give you.

Posted by shafa.fahad (FahaD), 27 September 2006
Thanks Graham..

It would be very thankful if I can get some ideas on expecting from the process and keyboard at the same time....

The scenario i have is that,

I login to remote machine and execute commands over there, so i have spawned ssh <machine>. I would like to stop execution at the remote machine when user press "q" [User will also be entering password while doing ssh]

I have included a code snippet for your reference:

spawn ssh $remotemachine@$ip
expect Password: {
       stty -echo
       expect_user -re "(.*)\n"
       send_user "\n"
       send "$expect_out(1,string)\r"
       stty echo
expect -re $prompt
send "tail -100f $filepath/$filename\r"
<Here is where i want to expect "q" from user and terminate tail command>

You have mentioned about spawing new tail command.... and expecting from both process using "expect -i"

I understand the usage of "expect -i" as below....

expect {
       -re $prompt  { send "exit\r" }
      -i $anotherprocess_id  busy {puts busy\n ; exp_continue} -->  what should i use here to expect from keyboard

which means we are expecting
"busy" from the process whose spawn_id is $anotherprocess and
prompt from the current process

But i am not clear about expecting from current process and user at the same time

Please add ur advice...


Posted by admin (Graham Ellis), 28 September 2006

spawn ping
lappend spid $spawn_id
spawn ping
lappend spid $spawn_id

puts $spid

while 1 {
expect {
       -i $user_spawn_id "q" {puts hello; exit}
       -i $spid "\n" {puts world}

Posted by shafa.fahad (FahaD), 28 September 2006
Thanks Graham....

That helped a lot...  

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