problem with executing linux program in perl
$a=`myexecutable`;
print $a;
I want to run a executable in perl, but above code only ouput the whole
screen output once the whole program finished run of its last statement
(take 20 seconds to run the program and wait 20 seconds to see the
output). I wish to be able see the output once the program write to std
output. How to do it?
Re: problem with executing linux program in perl
david wolf wrote:
> $a=`myexecutable`;
>
> print $a;
>
> I want to run a executable in perl, but above code only ouput the whole
> screen output once the whole program finished run of its last statement
> (take 20 seconds to run the program and wait 20 seconds to see the
> output). I wish to be able see the output once the program write to std
> output. How to do it?
Instead of executing the program through the shell, open a pipe to the
program, and read from the handle.
open my $handle, '-|', 'myexecutable' or die "Could not run
myexecutable: $!";
while (<$handle>){
print;
}
read more in:
perldoc -f open
perldoc perlopentut
Paul Lalli
Re: problem with executing linux program in perl
Thank you so much, Paul. I'll try your suggestions.
Re: problem with executing linux program in perl
"david wolf" <yihucd [at] gmail.com> wrote in message
news:1129915767.454881.72530 [at] g49g2000cwa.googlegroups.com...
>
> $a=`myexecutable`;
>
> print $a;
>
> I want to run a executable in perl, but above code only ouput the whole
> screen output once the whole program finished run of its last statement
> (take 20 seconds to run the program and wait 20 seconds to see the
> output). I wish to be able see the output once the program write to std
> output. How to do it?
system "myexecutable" and die "Can not run myexecutable $!\n";
Re: problem with executing linux program in perl
Thanks, Tintin. it's really nice to get your suggestion.