Reputation: 127
I understand that backticks
can be used for retrieving the output of a command after it has finished execution but I don't know how to read outputs as they come in while the command is still executing or how to do this with multiple terminals at the same time.
The OS the script is runnning on is Ubuntu 17.04
Upvotes: 3
Views: 875
Reputation: 69264
If you have a question about Inter-Process Communication in Perl, then the perlipc manual page might be a good place to start. Specifically, in this case, the section on Using open()
for IPC seems useful.
Basically, you can use open()
to open a handle onto a process which you can then read data from in the same way as you read data from any filehandle.
The example in the document uses netstat
:
open(STATUS, "netstat -an 2>&1 |")
|| die "can't fork: $!";
while (<STATUS>) {
next if /^(tcp|udp)/;
print;
}
close STATUS || die "bad netstat: $! $?";
Upvotes: 2