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!

controlling external programs/commands

Status
Not open for further replies.

howdthattaste

Programmer
Apr 12, 2007
17
US
OS:Win Xp
My example here seems pointless, but the method (if possible) would solve my problem.


In windows, we have the command 'pause'. Its simple, and usually used at the end of batch files. You can also type it on the command line. At which point you're prompted to "press any key to continue...".

I can call this with perl with:
open(PAWZ,"pause |");
while(<PAWZ>)
{
print "$_\n";
}


However, once that happens im suspended until I physically press a key. The question: Is there anyway to have the perl script issue the keystroke? In this case id be interested in having it simulate pressing the 'e' key to unsuspend and continue on through the perl script.

Thanks!



----------------------------------
"Not New York..., Kansas
 
Not sure, but have you tried issuing a command with system or with backticks or qx?
 
You call pause. You block waiting on your synchronous call. Pause blocks waiting for I/O. Your calling process does not get scheduled again until this happens.

You could devise some massively complex threaded solution, but what is the benefit? How long should it wait before automatically replying 'e'? Could you not achieve the same effect with a call to 'sleep'? Why would you bother?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
thanks stevexff,

basically, the app i want to call starts some server stressing. It wont stop until the user presses 'e'.

I want my perl script to initiate the stressing, then do some log checking, etc, then tell the app to stop so i can move on to the next server.

i thought the 'pause' command was an okay example; its doing its thing (suspending) until the user interacts.

The downside for me is that while the app is doing its thing, i can't do anything else... or tell it to stop. (at least i dont know how)

yes, i was thinking about threading, where i can start the app with one thread, and go check logs with another thread. But how do I go back to the app thread and give it an 'e' when im done?

thanks again.

----------------------------------
"Not New York..., Kansas
 
If you have a sleep command available (Cygwin is an option if you don't) you might be able to do something like this:

Code:
#!/usr/bin/perl -w

system("( sleep 5 && echo ) | pause");

Annihilannic.
 
howdthattaste said:
My example here seems pointless
Sorry, I wasn't intending to give you a hard time, but I needed a bit of context to understand the problem... [smile]


You don't need to do the log analysis in parallel with the stress test, can you do them serially? This would avoid a threaded solution unless you have 30 or 40 servers to test. Are there any command line options to the 'stress' command that would enable you to script it more effectively? e.g. stress --stopaft 60? I appreciate tht WinXP stuff is usually less script-friendly so this might not be the case. Is it a third party utility, or can you modify it yourself?

Failing that, Annihilanic's suggestion might be worth pursuing.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top