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

Dear monks,

I need to read STDERR and STDOUT simultaneously, and I decided to use IPC::Open3.

I am on Win32, and system(".... 2>& 1 |") trick works not very good.

Does anyone knows internal details whether or not IPC::Open3 uses temporary files to provide this functionality?
I hope not, but would be glad to hear a bit of knowledge from others on this.

PS. I know temporary files ar enot very bad, but still want to avoid them for my particular task.

Best regards,
Courage, the Cowardly Dog

Replies are listed 'Best First'.
Re: Does IPC::Open3 uses temporary file?
by gellyfish (Monsignor) on Dec 02, 2004 at 14:57 UTC

    Nope, it uses pipe() where it can, otherwise doing some duping tricks. So you are alright.

    /J\

      thanks!
Re: Does IPC::Open3 uses temporary file?
by DrWhy (Chaplain) on Dec 02, 2004 at 15:42 UTC
    Speaking as a veteran of many fights with IPC::Open3, I would recommend to you that there are other simpler and less problematic methods to separately capture STDOUT/STDERR from subprocesses. IPC::Run is much better at doing this simply and reliably.

    There are several other CPAN modules that appear to do this in an even simpler manner than IPC::Run; IO::CaptureOutput, and System2 are two examples. I haven't used these two modules per se, so caveat programmor.

    Open3 is actually pretty powerful, but with the power comes complexity -- using it feels like programming in C, and it's very easy to get yourself deadlocked if you don't manage your io handles carefully.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      Your post was of really much help to me, thanks.

      I tried open3 and almost succeeded, but, while asimptotically reaching final result, I still had no success on that way.

      I gained my goal using namely IPC::Run. I was stuck several times with "Win32 limitations" described in that module, however, but finally I got it.

      Finally, a program that implements quite simple thing (from unexperienced point of view), become quite complicated, but it works and hopefully does not stuck.

      I can show a code, if anyone interested on what it finally looks like.

      Best regards,
      Courage, the Cowardly Dog

Re: Does IPC::Open3 uses temporary file?
by fglock (Vicar) on Dec 02, 2004 at 15:42 UTC

    You can call open3 with

    open3( $write_fh, $read_fh, $read_fh, ... )

    (I actually use this in a module that works in Windows)

Re: Does IPC::Open3 uses temporary file?
by zentara (Cardinal) on Dec 03, 2004 at 11:21 UTC
    I need to read STDERR and STDOUT simultaneously

    In IPC::Open3, if you set the STDERR filehandle to 0, it will be automatically combined with STDOUT.

    #my $pid = open3(\*WRITE, \*READ, \*ERROR,"bc"); my $pid = open3(\*WRITE, \*READ,0,"bc"); #if \*ERROR is false, STDERR is sent to STDOUT

    I'm not really a human, but I play one on earth. flash japh
      Thanks, very interesting information...

      It will not help me in my case (I can't mix STDERR and STDOUT, I should differentiate those) but this could help me in a next similar problem...

      Now I don't remember exact details (I am home, and that Perl program at work) but I suceeded mixing STDERR and STDOUT by something like this:

      open my $fhcmd, "$cmd args 2>&1 |";

      Best regards,
      Courage, the Cowardly Dog