[Israel.pm] print to 2 places at the same time
eli at billauer.co.il
Tue Jun 1 12:52:44 PDT 2004
Correct me if I'm wrong, but as long as one path goes through an
external process and the second goes directly from Perl's "print", there
is no way to control which comes first. In particular, you have no way I
can think of to be sure that the application "tee" has finished sending
I would suggest to use a Perl module named IO:Tee from CPAN. Never tried
it, but how bad can it bee? ("bee" as in "tee").
That would make sure that the order of output is kept, with no
Offer Kaye wrote:
>I'm trying to use advice from "perlfaq5" and print to 2 places at once
>(STDOUT and a file) using "tee". However, in my case I have to intercept the
>prints to the filehandle with prints just to STDOUT. Example code:
>open(OUT,"| tee foo.txt") or die "tee foo no good: $!\n";
>print OUT "foobar\n";
>print OUT "barfoo\n";
>close(OUT) or die "wtf?\n";
>The problem is, the above doesn't print:
>As you would expect. It instead prints:
>This happens even of I do "$|=1;" at the beginning of the script.
>Anyone have any idea what is happening?
>Anyone have any workaronds?
>Thanks in advance,
>Perl mailing list
>Perl at perl.org.il
More information about the Perl