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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.