This may very well be a unix thing, not a perl thing,
but I'm not a unix expert, so I'm not sure.
I have a tool I run in a shell script.
-------------------------------------------------------
#!/bin/csh
tool -options -nobuffer
-------------------------------------------------------
The -nobuffer is trying to get it to flush its output
to STDOUT, rather than buffer it a block at a time.
It prints out extremely long lines to STDOUT.
So, I made a perl script that takes in stdout,
does a s/// on the input, and sends it back to stdout.
-------------------------------------------------------
#!/opt/perl_5.8.8/bin/perl
use warnings;
use strict;
# turn off stdout buffering... hopefully.
$|=1;
if(scalar(@ARGV)==0){
$piped=1;
} elsif(scalar(@ARGV)==1){
$piped=0;
my $inname = $ARGV[0];
$outname = $inname.'.short.log';
}
my $content;
while(<>){
my $line = $_;
my $orig=$line;
if($line=~s///){
if($line=~s///}){
}
}
if($piped){
print $line;
} else {
$content .= $line;
}
}
if($piped==0){
open(my $outh, '>'.$outname) or
die "ERROR: unable to open for write '$outname'";
print $outh $content;
close($outh);
}
-------------------------------------------------------
So, when I run it on the command line, it works fine:
prompt> tool -options -nobuffer | filter.pl
The output looks exactly like I want.
And when I hit <control>-C, it exits immediately.
But when I put it into the shell script:
-------------------------------------------------------
#!/bin/csh
tool -options -nobuffer | filter.pl
-------------------------------------------------------
It looks fine, but it hangs when I hit <control>-C.
I don't know if this is a side effect of the way the shell script works.
If its a side effect of the perl script.
if its something to do with flushing STDOUT.
If I hit control-c when its clearly not in the regular expression area,
I can sometimes get it to exit immediately. But once the tool reaches
a certain point, every line is going through the regular expression,
and at that point, control-C seems to stop execution, but refuses
to give me a prompt back.
I don't think I've ever written a perl script that takes a pipe input
so I don't know if there is some side effect about pipes, perl, and
control-C maybe?
Any ideas?
Greg London
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm