Yes, the problem is that the <> is a blocking read, which means the program is hung-up waiting for some data to arrive.

The usual way to handle this is easier than the thread mentioned by Zentara. There is an alarm that can interrupt program's execution when it counts down to zero seconds. See below for typical code. alrm_handler() is a subroutine that gets called when the alarm expires.

Note loop construction. I like to do it this way because I can see all 3 things that can cause the loop to stop all at once right there in the in the while() statement: (1) alarm, (2) no data (EOF), (3) or line text matches "DONE".

The alarm() is separated by a comma (yes, there is a comma operator). The "truth or falseness" of the of a comma joined statement is simply the last statement. This comma joined statement has the advantage that (1) no extra alarm() statement is needed before the while() statement and (2) if for some reason there are "next's" or various ways the loop can restart, I won't fail to restart the alarm (could happen if the alarm restart has to be embedded within the loop). Oh, and first thing to do within the body of the loop is to deactivate the alarm! Well unless of course the total time that you are trying to measure includes the processing time of the loop, but usually this is not the case.

$SIG{ALRM}=\&alrm_handler; sub alrm_handler { do...something here... sounds like die and cause shell command to be re-executed... } my $inLine; while (alarm(20), $inLine = <> and $inLine !~ /^Done/) { alarm(0); # deactivate the alarm!! normal loop here... } print "Exiting\n"; exit;

In reply to Re: Detecting Timeout of piped data by Marshall
in thread Detecting Timeout of piped data by sriordan

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.