wrote:
>>It's not the Perl script's fault that the Tcl interpreter buffers its
>>output.
>>There is little you can do in your Perl script to correct that.
>
>
> that is not true.
>
> #!/usr/bin/perl -w
> select STDOUT;
> $|=1;
> print `echo test;sleep 5;echo test`;
> __END__
>
> o/p:
> time goes by 5 seconds
> test
> test
> #!/usr/bin/perl -w
> select STDOUT;
> $|=1;
> print system "echo test;sleep 5;echo test";
> __END__
>
> o/p:
> test
> time goes by 5 seconds
> test
>
Note that a "0" is also printed, but you don't show it:
josef@bounty:~> perl
print system "echo test;sleep 5;echo test";
test
test
0josef@bounty:~>
^
The difference between the two examples is that the return value of the
back-quoted command sequence is the output of the command sequence while
the return value of the "system" command is the exit status of the
executed command (a shell, in this case as the string contains shell
meta characters).
I.e. in the first case, "print" prints the two "test"s while in the
second case, the two "echo"s print the "test"s.
Try
my $x = `echo Test1`;
my $y = system("echo Test2");
See?
If not, add
print "x=$x\ny=$y\n";
>>I almost wrote "nothing you can do" as there is a solution:
>>do not run your Tcl script through a pipe but rather set up a pseudo-tty
>>between the Perl and the Tcl script. That way the Tcl script will assume
>>a terminal on its stdout (which, in effect, it has) and will send
>>line-buffered output.
>>
>>Expect (a Tcl based software) does that.
>
>
> Actually I wasn't doing fully disclosing all the details, the script
> called by Perl is a Expect script
> most of it Tcl. I think I am correct in saying that the "puts" Tcl
> function is unbuffered.
It appears I'm wrong in assuming that Tcl's output is buffered: it's not:
test.tcl:
puts "line1"
exec /bin/sleep 10
puts "line2"
test.pl:
open(my $tcl, 'tclsh test.tcl|');
select STDOUT; $|=1;
while (<$tcl>) {
print;
}
prints the two lines with a 10s delay in between.
> So what I experienced is a difference between backtick and system
> command.
The work differently. Therefore there is a difference.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett