in reply to Script hangs when called via IPC::Open3

jeffa,
Hi guys, long time listener first time caller.

So the calls before were crank calls or did you think it was a different radio station back then?

Ok, seriously I know this doesn't help you at all with your problem but it is nice to point out every now and then how much of a contribution some monks make. You have been a monk since 2000-06-19 and have posted 2,346 times (as of this posting). Of those, only 20 are questions and it has been over 3 years since your last one. Thanks - hope you find the help you need given how much you have provided others.

Cheers - L~R

  • Comment on Re: Script hangs when called via IPC::Open3

Replies are listed 'Best First'.
Re^2: Script hangs when called via IPC::Open3
by jeffa (Bishop) on Jun 28, 2006 at 15:15 UTC

    Oh ... um ... those were like ... other jeffas ... or something. Huh huh huh huh.

    Big thanks for the compliments, L~R, and a big thanks to everyone else on this thread for providing great answers and work arounds. I believe i am simply going to remove the wait() call as i really don't need to query the exit status of the exec'ed script after all. I am trying to avoid storing STDOUT and STDERR into scalars as well, hoping to keep them out of memory any more than necessary. Unfortunately, it seems to me that using backticks and shell redirection is the best way to go with this ... i was trying to avoid that, but i am also likely being too pedantic.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Moving the wait is not enough

      +------------------------+----------------------+ | Parent | Child | +------------------------+----------------------+ | - open3(...); | | | - <OUT> | - ... | | | - Waits for child to | - print STDERR 1027; | | | write to STDOUT or | - print STDERR 1028; | | | for child to end. | - print STDERR 1029; | T | | - print STDERR 1030; | i | | - print STDERR 1031; | m | | - Pipe full. | e | | Waits for parent | | | | to empty it. | | | | | v | Still waiting... | Still waiting... | +------------------------+----------------------+

      With my snippet below, you don't have to store the stuff in memory. You can do whatever you want to with it when you read it it. For example, the following prints it out a line at a time, prefixed with the handle name:

      my %lookup = ( \*OUT => [ \*OUT, 'STDOUT', '' ], \*ERR => [ \*ERR, 'STDERR', '' ], ); MAIN_LOOP: for (;;) { my @r = $r_sel->can_read(); foreach my $fh (@r) { last MAIN_LOOP if eof($fh); my $buf_ptr = $lookup{$fh}[2]; 1 while read($fh, $$buf_ptr, $BLOCK_SIZE, length($$buf_ptr)); print("$lookup{$fh}[1]: $1") while $$buf_ptr =~ s/^(.*\n)//; } } foreach my $fh (keys %lookup) { print("$lookup{$fh}[1]: $lookup{$fh}[2]\n") if length $lookup{$fh}[2]; }

      Alternatively, you could use IPC::Run. Instead of a scalar, you can pass the address of a callback to be called when text is received from the child. (Search for \&out.)