In Perl, I can open a child process and pipe its output to the calling Perl script, like this:
open(my $cmd, '-|', 'ls') or die $!;
while (<$cmd>) {
print $_;
}
This prints the files in my working folder, e.g.:
> foo.txt > bar.txt > ...
But I would like to do the same thing for a child process that remains open, e.g. to pipe tcpdump
's stdout to Perl, I attempt something similar:
open(my $cmd, '-|', 'tcpdump') or die $!;
while (<$cmd>) {
print $_;
}
... but other than the tcpdump
startup text, this doesn't mete out any http logs. It just seems to hang. What gives?