How to clear output in backticks in Perl?

If I have this perl application:

print `someshellscript.sh`; 

which prints a bunch of things and takes a lot of time, how can I print this output in the middle of a shell script execution?

It seems that Perl will only print the result of someshellscript.sh when it is complete, is there a way to make the output stream in the middle of execution?

+7
perl backticks
source share
2 answers

What you probably want to do is something like this:

 open(F, "someshellscript.sh|"); while (<F>) { print; } close(F); 

someshellscript.sh is someshellscript.sh and opens a pipe that reads its output. The while reads each line of output generated by the script and prints it. See the open documentation page for more information.

+16
source share

The problem is that escaping with backticks saves your script in a string that you then print. For this reason, there would be no way to β€œrinse” the seal.

Using the system () command should continuously print the output, but you cannot capture the output:

 system "someshellscript.sh"; 
+3
source share

All Articles