| Author |
problem with executing linux program in perl
|
|
| david wolf 2005-10-21, 6:56 pm |
|
$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?
| |
| Paul Lalli 2005-10-21, 6:56 pm |
| 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
| |
| david wolf 2005-10-22, 3:55 am |
| Thank you so much, Paul. I'll try your suggestions.
| |
| Tintin 2005-10-26, 6:56 pm |
|
"david wolf" <yihucd@gmail.com> 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";
| |
| david wolf 2005-10-31, 6:58 pm |
| Thanks, Tintin. it's really nice to get your suggestion.
|
|
|
|