Hi Monks,

I have a setup script(A) which triggers one of my scripts(B) in which I invoke another script(C) using qx//. The invoked script (C) might take hours for completion and the output of the same is captured in a variable to error checking and parsing the results.

$exec_status = `$cmd 2>&1`;

But the problem is that, the setup script(A) actually looks for some messages printed on the console or else it will timeout after waiting for a fixed time. So is there any way I can use in my script (B) which actually does not wait for the script (C)'s completion and print something on the STDOUT periodically like "Waiting for $timout seconds..".

When I use backtick, the script B waits till the script C's completeion which is a very long time. The use of system() works for me which prints to STDOUT, but I cannot parse the output of script C.

So basically I just want to combine the functions of backtic and system() which is not possible as far as I know. If I redirect output to a file how will I monitor that the execution is completed and EOF has reached if I use the below method.

$timeout=1000; open (FP, "scriptC.pl |") or die 'Error'; while (<FP>) { $output .= $_; sleep 30; $timeout -=30; print 'Waiting for execution to finish'. $timeout; }
Hope you can pour some insights to this.

In reply to Capturing output of qx// without waiting for completion by ajose

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.