Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I too have had issues with alarm() on Windows. This is a quick workaround - not very efficient or accurate, but close to the timeout you want. $timeout is number of seconds to run before timing out.

NOTE: I need an "infinite output" .exe so the './test.exe' program just prints numbers 1 .. 100000 to the screen. I set my $timeout for 2 seconds.

use strict; use warnings; my $pid = open(my $fileHandler, '-|', "./test.exe" ); my $start = time; my $timeout = 2; while (<$fileHandler>) { print "$_\r"; # \r to not overrun output screen buffer last if ((time - $start) >= $timeout); } print "\nTimeout! - Time to kill pid: $pid\n"

And the output:

VinsWorldcom@C:\Users\VinsWorldcom\tmp> TimeThis test.pl TimeThis : Command Line : test.pl TimeThis : Start Time : Fri Oct 12 10:42:04 2012 56464 Timeout! - Time to kill pid: 4192 TimeThis : Command Line : test.pl TimeThis : Start Time : Fri Oct 12 10:42:04 2012 TimeThis : End Time : Fri Oct 12 10:42:06 2012 TimeThis : Elapsed Time : 00:00:01.903

Of course you could maybe use Time::HiRes to get more accurate.


In reply to Re: Windows run an exe print its output and cut it off after a time by VinsWorldcom
in thread Windows run an exe print its output and cut it off after a time by anshumangoyal

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (12)
    As of 2014-09-17 16:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (91 votes), past polls