I am writing some test scripts for a small project that I am working on. Basically, the project involves the running of a Command Line Interface (CLI) tool (my creation) and the test needs to process and verify that the output is the expected result. Simple.
However, there are circumstances where the CLI could hang or wait on a response for a very long time due to the CLI interacting with hardware and the hardware not responding due to some internal hardware error.
$cmd = "MyProgram.exe"; $output = `$cmd`; # The problem I am facing at this point is, if # "MyProgram.exe" hangs, or takes a long time to # respond, the script will not be able to process # the output or proceed to run other tests.
I was wondering if there was any way where after the call to my external program is made, and given a fixed waiting period, a timeout or termination of my external program can be issued? After the timeout or termination the CLI's process, I intend to continue running other scripts, somewhat like an automated test.
I have tried to use alarm() previously but was not able to get it to work.
I found that since I was feeding the output of the external program to a variable (which I need for processing), the control does not return to the script until the external program exits. So, if the external program goes into an infinite loop, the alarm raised would not be able to be handled because the external program will still be hogging the control.
Anyone able to help?
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |