Edmond Rodriguez on 1 Dec 2014 07:10:10 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] Fwd: Flushing buffers with perl and called process


Consider the perl program below.  The perl program is writing to
stdout, and it calls to another process that writes to stdout.    What
usually results is all the perl code output displayed and the systems
calls output being delayed and all displaying at the end.

so instead of 1,2,1,2.....   one gets 2,2,2,2,2,.......1,1,1,1,1

I have read articles about flushing buffers, making filehandles "hot" etc...

What is the best way to get the output to come out in the same order
the program is written (such that buffers always flush out before the
next is written?

Thanks for any opinions,

Edmond

(I took some of the hot file handle code before from another
forum/article), but that would not apply to the process being called.

-----------------------------------

{my $ofh=select BASH; $|=1;
        select STDOUT; $|=1;
select $ofh; }

open(BASH, "|bash");

{my $ofh=select BASH; $|=1;
        select STDOUT; $|=1;
select $ofh; }

print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";
print BASH "echo hello 01\n";
print "hello 02\n";

close BASH;
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug