| |||||||||||
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:
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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |