in reply to Asynchronously capturing output from an external program

open(my $fh_from_child, '-|', 'perl', "$home/filtered.pl")

Keep in mind that the child might buffer its output when it's not connected to a terminal. If the reader hang, it could simply mean the child hasn't emptied its buffer yet. Using a pseudo tty (like Expect does) usually convinces the child not to buffer its output.

Update: Added paragraph about buffering.

Replies are listed 'Best First'.
Re^2: Asynchronously capturing output from an external program
by Furple (Novice) on Nov 09, 2010 at 17:55 UTC
    File handle worked just fine. ...now I'm trying to get the output back out of it. Now I'm hanging when I try to extract the output from the handle. My code looks like:
    print "\n PROCESSING \n\n"; while (<$fh>) { print "$_ \n"; if($_ =~ m/"urlid":"(.*?)"/) { print "found it! \n"; $target = $1; print "terminating \n"; last; } }
    I get "Processing" and then the first line from the output before it just hangs. I'm not entirely sure what's going on there. I'll try messing around with Expect and see if I can get that to work.

      I get "Processing" and then the first line from the output before it just hangs

      So it's waiting to receive a newline from the child. The child hasn't sent one at all, or it's waiting in a buffer the child hasn't flushed.