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?
David Wolf [ Fr, 21 Oktober 2005 19:29 ] [ ID #1024293 ]

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
Paul Lalli [ Fr, 21 Oktober 2005 19:44 ] [ ID #1024294 ]

Re: problem with executing linux program in perl

Thank you so much, Paul. I'll try your suggestions.
David Wolf [ Sa, 22 Oktober 2005 06:29 ] [ ID #1025359 ]

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";
Tintin [ Mi, 26 Oktober 2005 21:58 ] [ ID #1031327 ]

Re: problem with executing linux program in perl

Thanks, Tintin. it's really nice to get your suggestion.
David Wolf [ Mo, 31 Oktober 2005 20:49 ] [ ID #1037816 ]
Perl » alt.perl » problem with executing linux program in perl

Vorheriges Thema: $_ and @_
Nächstes Thema: Saving variables over multiple pages