problem with executing linux program in perl

problem with executing linux program in perl

am 21.10.2005 19:29:27 von David Wolf

$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

am 21.10.2005 19:44:07 von Paul Lalli

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

am 22.10.2005 06:29:05 von David Wolf

Thank you so much, Paul. I'll try your suggestions.

Re: problem with executing linux program in perl

am 26.10.2005 21:58:54 von Tintin

"david wolf" wrote in message
news:1129915767.454881.72530@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

am 31.10.2005 20:49:21 von David Wolf

Thanks, Tintin. it's really nice to get your suggestion.