Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/using-interact.html

Our email: info@wellho.net • Phone: 01144 1225 708225

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

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

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,
Fahad

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.

Thanks

Graham

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

Thanks
Fahad

Posted by admin (Graham Ellis), 28 September 2006
Example:

Code:
spawn ping 192.168.200.134
lappend spid $spawn_id
spawn ping 192.168.200.189
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 www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© 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: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho