Walt Mankowski on 1 Dec 2014 13:03:56 -0800


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

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


Do you need to send commands to the external program as you're doing
in this example?  If you don't, then you could redirect the program's
output back to your perl script (by putting the | on the other end of
the process name) and then have your script handle all the writing to
STDOUT.

On Mon, Dec 01, 2014 at 03:10:04PM +0000, Edmond Rodriguez wrote:
> 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

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
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