boom has asked for the wisdom of the Perl Monks concerning the following question:

If I have this perl app:

print `someshellscript.sh`;

that prints bunch of stuff and takes a long time to complete, how can I print that output in the middle of execution of the shell script? Looks like Perl will only print the someshellscript.sh result when it completes, is there a way to make output flush in the middle of execution?

Replies are listed 'Best First'.
Re: How to flush output in backticks In Perl?
by Bloodnok (Vicar) on Apr 18, 2009 at 12:51 UTC
    It all depends what you want to achieve ... your snippet merely runs a script in the backticks i.e. does nothing with/has no interest in any output to either of the standard output devices - if all you want is to see the output as the script runs, use system.

    OTOH, if you are interested in any the output from the script, then follow the advice given in the earlier AM posting.

    A user level that continues to overstate my experience :-))
Re: How to flush output in backticks In Perl?
by graff (Chancellor) on Apr 19, 2009 at 04:50 UTC
    Have you tried this:
    $| = 1; # don't buffer output open( SH, '-|', 'someshellscript.sh' ) or die "Can't run someshellscri +pt.sh: $!"; while (<SH>) { print; }
    Stuff coming from the shell script might still get buffered, but if there's more than one buffer's worth, you'll see each buffer-load as soon as it happens.
Re: How to flush output in backticks In Perl?
by Anonymous Monk on Apr 18, 2009 at 11:38 UTC