D
Dilbert
I have the following program:
use strict;
use warnings;
# redirect STDOUT to a file, but keep output to
# screen alive (via the "tee" command)
open STDOUT, "| tee logfile.txt" or die "Error: $!";
print "abc", "z" x 30, "enter a number >";
my $num = <STDIN>;
print "\nYou entered: $num\n";
When I run this program, I see
abczzzzzzzzzzzzzzzzzz
but I can see no prompt "enter a number >"
the cursor waits after the "...zzzz"
I can blindly type in a number (e.g. 123), when I do this, I see the
following on my screen:
abczzzzzzzzzzzzzzzzzz123
zzzzzzzzzzzzenter a number >
You entered: 123
The problem here is that STDIN and STDOUT are not synchronized anymore
(probably due to the previous open STDOUT, "| tee logfile.txt"). --
and by synchronized I mean that the STDOUT buffer is flushed before
every read from STDIN.
How can I teach perl that STDOUT buffer is to be flushed before every
read from STDIN, even after an open STDOUT, "| tee logfile.txt".
I am on Ubuntu Linux:
This is perl, v5.10.1 built for i686-linux-thread-multi
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2009, Larry Wall
Binary build 1006 [291086] provided by ActiveState http://www.ActiveState.com
Built Aug 24 2009 13:45:03
use strict;
use warnings;
# redirect STDOUT to a file, but keep output to
# screen alive (via the "tee" command)
open STDOUT, "| tee logfile.txt" or die "Error: $!";
print "abc", "z" x 30, "enter a number >";
my $num = <STDIN>;
print "\nYou entered: $num\n";
When I run this program, I see
abczzzzzzzzzzzzzzzzzz
but I can see no prompt "enter a number >"
the cursor waits after the "...zzzz"
I can blindly type in a number (e.g. 123), when I do this, I see the
following on my screen:
abczzzzzzzzzzzzzzzzzz123
zzzzzzzzzzzzenter a number >
You entered: 123
The problem here is that STDIN and STDOUT are not synchronized anymore
(probably due to the previous open STDOUT, "| tee logfile.txt"). --
and by synchronized I mean that the STDOUT buffer is flushed before
every read from STDIN.
How can I teach perl that STDOUT buffer is to be flushed before every
read from STDIN, even after an open STDOUT, "| tee logfile.txt".
I am on Ubuntu Linux:
This is perl, v5.10.1 built for i686-linux-thread-multi
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2009, Larry Wall
Binary build 1006 [291086] provided by ActiveState http://www.ActiveState.com
Built Aug 24 2009 13:45:03