At least on Unix and Unix-like systems, it seems to me that your master script should not be blocked. This is a quick test. First, the subprogram, which is turning off IO buffering and writing a number every 3 seconds:

# sub_program use strict; use warnings; { my $fh = select STDOUT; # making STDOUT "hot" (no IO buffering) $| = 1; select $fh; } for my $i (0..100) { print "$i \n"; sleep 3; }
Now the master program, which is reading every 10 seconds the full file produced by the subprogram and prints out the last line:
# main program use strict; use warnings; system ("perl sub_program.pl > file.txt &"); my $last_line; for my $i (0..100) { sleep 10; local @ARGV = ("file.txt"); $last_line = $_ while <>; print "iteration $i : $last_line"; }
Now running the master program:
$ perl test_sub.pl iteration 0 : 3 iteration 1 : 6 iteration 2 : 9 iteration 3 : 13 iteration 4 : 16 ...
As you can see, the master program ("test_sub.pl") is perfectly able to read the file generated by the subprogram, even though the subprogram is still running. Maybe your problem is that you did not think about turning off IO buffering.


In reply to Re: Reading a file live! by Laurent_R
in thread Reading a file live! by negativ_m

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.