in reply to Re: open3 and IO::Select
in thread open3 and IO::Select

After some debugging, I found that open3 defaults to using the same pipe for the child's STDOUT and STDERR.
Yes. It's easy to skip over that fact, but it is in the documentation:
       Extremely similar to open2(), open3() spawns the given $cmd and con-
       nects RDRFH for reading, WTRFH for writing, and ERRFH for errors.  If
       ERRFH is false, or the same file descriptor as RDRFH, then STDOUT and
       STDERR of the child are on the same filehandle.
So the only filehandle that needs to be directly set is ERRFH. You can leave the other two alone.
(WTF?!? I'd use open2 if I wanted to do that.)
Not in the same way. You might use a shell to redirect STDERR to STDOUT and then read that new (combined) stream with open2, but you cannot use open2 to read STDERR directly. That's a different behavior from open3 making both streams available on the same perl filehandle (without needing an intervening shell for the redirection).
--
Darren

Replies are listed 'Best First'.
Re^3: open3 and IO::Select
by Anonymous Monk on Apr 14, 2009 at 13:01 UTC

    I realise I come very late in this exchange, but just in case people are still looking for answers, I got it to work with cygwin perl on Windows XP with the following tweaks :

    1/
    use IO::Select; use IO::Socket; use IO::Handle; use IPC::Open3;
    2/
    $Pin = new IO::Handle; $Pin->fdopen(10, "w"); $Pout = new IO::Handle; $Pout->fdopen(11, "r"); $Perr = new IO::Handle; $Perr->fdopen(12, "r"); $Proc = open3($Pin, $Pout, $Perr, $cmdline);
    3/
    $select->add($Pin); $select->add($Pout); $select->add($Perr);

    For $cmdline I used bash, to test things by hand (with STDIN added to my select and printing on $Pin what I get on my perl process' stdin).

    It works beautifully.