in reply to Re: Weirdness with IO::Select and IPC::Open3
in thread Weirdness with IO::Select and IPC::Open3

Hi ikegami, thanks for all the great responses. It's going to take me a while to study it all, but I was wondering--how would you do it without IO::Select? You seem to be suggesting it is less than ideal for the purpose, but all I know is when I google the errors I get when I don't use it, everyone says to use it :-).

Color me confused.

  • Comment on Re^2: Weirdness with IO::Select and IPC::Open3

Replies are listed 'Best First'.
Re^3: Weirdness with IO::Select and IPC::Open3
by ikegami (Patriarch) on Mar 21, 2011 at 04:40 UTC

    If you don't care about the child's STDERR, you can send it to the parent's STDERR (using '>STDERR' for open3's third arg). Then, all you need is

    ... while (<$stdout_fh>) { chomp; if (/Have a nice day!\z/) { print("$query\n"); } elsif ($answers{$query}) { print($stdin_fh "$answers{$query}\n"); } else { # ...[ Do something with unrecognised output from STDIN. ]... } }

    You can do this because you have a strict request-response protocol.

    If you had a more asynchronous protocol, you still have lots of simpler options than select. These include IPC::Run, Expect and threads.

    when I google the errors I get when I don't use it, everyone says to use it :-).

    What errors would that be?