Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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 TimeThis : Command Line : TimeThis : Start Time : Fri Oct 12 10:42:04 2012 56464 Timeout! - Time to kill pid: 4192 TimeThis : Command Line : 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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    [LanX]: met a guy from Aberdeen durin holidays, liked Scotsish accent a lot ... very phonetic
    [LanX]: ... understood everything after mentally write down what he said.
    [choroba]: Trainspotting?
    [choroba]: Ouch, trailing commas in JSON :-(
    [LanX]: ... though there seems to exist a taxation for the letter 't' in Northern Bri''ain ;-)
    [LanX]: never seen trainspotting in OV ... :(
    [karlgoethebier]: LanX
    [LanX]: They should teach Scottish in continental schools after Brexit !!!

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2018-02-19 10:42 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (261 votes). Check out past polls.