dracos has asked for the wisdom of the Perl Monks concerning the following question:

ok, I am having issues with the following code STDERR seems to be ending up in the STDOUT handle on the open3

#!/usr/bin/perl use strict; use warnings; use IPC::Open3; chdir "C:\\"; my ( $writer, $reader, $err, $pid ); my $SVN_LIST = "svn status --depth infinity --no-ignore C:\\Nonexistan +t_DIR"; $pid = open3( $writer, $reader, $err, $SVN_LIST ); waitpid $pid, 0; while (<$err>) { # causes "Use of uninitialized value $err in <HANDLE> +" print "$_"; # and "readline() on unopened filehandle" } while (<$reader>) { print "$_"; # Prints the error message } $SVN_LIST = `svn status --depth infinity --no-ignore C:\\Nonexistant_D +IR`; #error message comes out on STDERR since it isn't captured. print "$SVN_LIST"; # prints nothing.

when I run this the SVN command in a cmd shell it will return via STDERR "svn: warning: 'C:\Nonexistant_DIR' is not a working copy". I have proved it to myself by running the following on a command prompt

svn status --depth infinity --no-ignore C:\NON_EXISTANT_DIR > xxx 2> e +rr

With this the file xxx is empty and the file err has the data in it.

What am I missing on the open3 that I am not getting STDERR output in what from my reading should be in the $err I pass.

Or is the issue I am having related to the fact I am running on a Windows platform

I am using activestate perl version v5.16.3 built for MSWin32-x86-multi-thread.

Replies are listed 'Best First'.
Re: Issues with IPC::Open3 on win32
by Don Coyote (Hermit) on Apr 01, 2014 at 22:21 UTC

    Hello dracos

    ok, I am having issues with the following code STDERR seems to be ending up in the STDOUT handle on the open3

    In the first paragraph of the Documentation for IPC::open3 http://perldoc.perl.org/IPC/Open3.html the behaviour you are describing as a problem is outlined.

    DESCRIPTION

    Extremely similar to open2(), open3() spawns the given $cmd and connects CHLD_OUT for reading from the child, CHLD_IN for writing to the child, and CHLD_ERR for errors. If CHLD_ERR is false, or the same file descriptor as CHLD_OUT, then STDOUT and STDERR of the child are on the same filehandle (this means that an autovivified lexical cannot be used for the STDERR filehandle, see SYNOPSIS). The CHLD_IN will have autoflush turned on.

    Your $err is uninitialised, so returns false of undef, and the module behaves accordingly.

    The SYNOPSIS of how to set the $err variable shows the use of the Symbol module and setting a literal, due to the autovivified lexical rule. You will need to look that up. The Documentation does mention that IPC::Run has better error handling so there is another option.

    Hth

Re: Issues with IPC::Open3 on win32
by zentara (Cardinal) on Apr 02, 2014 at 09:58 UTC