Re: Interactive programs & Teeing
- From: conrado.blasco@xxxxxxxxx
- Date: 27 Nov 2006 16:52:54 -0800
boyd wrote:
In article <1164665393.691544.228200@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
conrado.blasco@xxxxxxxxx wrote:
I'm trying to write an interactive script that gets commands from
STDIN, prints the results to STDOUT, *and* tees the results to a log
file.
My problem is that when I add the teeing line to the program (see
below), the script doesn't print anything to STDOUT anymore (not even
the prompt). When I comment out that line, everything works fine
(except that I don't get the log file).
(Well, it actually still prints something, but only when the session is
over.)
It seems to me that I'm missing something very obvious, but I can't
figure out... Any help appreciated.
Relevant excerpt below:
#!/usr/bin/env perl
use warnings; # Needed since '-w' won't work on the shebang line
use strict;
use File::Basename;
my $my_name = fileparse($0);
# STDOUT prints on the screen as well as on to log file
open (STDOUT, "| tee ./" . $my_name . ".log")
or die "Teeing error: $!\n";
my $prompt = "$my_name > ";
# Main loop, read and parse standard input
print $prompt;
while (<STDIN>) {
parse_cmdline($_);
print $prompt;
}
It sounds like a buffering problem. Try adding $|++; near the top.
Boyd
That worked, thanks,
Conrado
.
- References:
- Interactive programs & Teeing
- From: conrado . blasco
- Re: Interactive programs & Teeing
- From: boyd
- Interactive programs & Teeing
- Prev by Date: Re: Windows CE, Windows Mobile
- Next by Date: FAQ 1.13 Is it a Perl program or a Perl script?
- Previous by thread: Re: Interactive programs & Teeing
- Next by thread: Re: Interactive programs & Teeing
- Index(es):
Relevant Pages
|
|