I'm looking for a way to run a Windows executable repeatedly with varying commandline options using Active Perl 5.10. The problem I ran into was that the executable will sometimes hang and I was not able to find a way to get it to time out on its own in this case. I was able to get it run with:
use Win32::Process; Win32::Process::Create($processobj, "C:\\foo.exe", "foo -options_here" +, 0, NORMAL_PRIORITY_CLASS, ".") || die print Win32::FormatMessage( W +in32::GetLastError() ); $processobj->Wait(20000); $processobj->GetExitCode($return);
This works and does what I want it to except I have no means of capturing standard out (other than redirecting everything to a file). I've read the other posts about using cmd.exe and redirecting that to a file, but I need to be able to process standard out in the rest of the script for logging to make any sense. Is there a way to do this, or maybe some better completely different way to run windows executables with the ability to time out the process? I've tried the following as suggested elsewhere and it never actually timed out:
eval { local $SIG{ALRM} = sub {die "alarm";}; alarm(20); $return = `foo -options_here`; alarm(0); }; if ($@) { if ($@ =~ /alarm/) { print "timeout\n"; } else { die; } }
I know its anathema to perl gurus, but I really don't care mucha bout zombie processes and handling everything cleanly as I'm just running this on a laptop. I really just need to be able to report where the executable is running fully and where its failing.
In reply to Win32::Process output by tawnos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |