sgifford has asked for the wisdom of the Perl Monks concerning the following question:
I'm having some trouble with IPC::Open3. Here is a test script that demonstrates the problem:
The expected output from this is:#!/usr/bin/perl use warnings; use strict; use IPC::Open3; # Basic setup stuff open(SAVE_STDOUT,">&",STDOUT) or die "save stdout failed"; open(DEVNULL,"< /dev/null") or die "open /dev/null failed"; # Now set STDOUT to a filehandle on a new descriptor open(FH1,"> /dev/null") or die "open /dev/null failed"; *STDOUT = *FH1; # Run the command open3(*DEVNULL, *PIPE, undef, "/bin/sh","-c",<<EOF) or die "open3 fail +ed"; printf "out 1\\nout 2\\nout 3\\n" printf "err 1\\nerr 2\\nerr 3\\n" >&2 EOF ; # And copy the output open(STDOUT,">&",*SAVE_STDOUT) or die "restore stout failed"; while (<PIPE>) { print "PIPE: ",$_; } close(PIPE) or die "close pipe failed"; exit(0);
which indicates that the child process had both standard output and standard error sent to the pipe created by open3. Instead, with both IPC::Open3 1.02 and 1.03, I get this output:PIPE: out 1 PIPE: out 2 PIPE: out 3 PIPE: err 1 PIPE: err 2 PIPE: err 3
This indicates that the standard output from the script didn't go through the pipe. Instead it went directly to my terminal, where file descriptor #1 is connected to in the parent process.out 1 out 2 out 3 PIPE: err 1 PIPE: err 2 PIPE: err 3
This appears to be the result of a bug in IPC::Open3, which I reported in Perl bug #66224, including a patch. I wanted to see if my fellow Monks had any insight or ideas for a better fix/workaround.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IPC::Open3 misbehaving when STDOUT is not FD #1
by ikegami (Patriarch) on Jun 05, 2009 at 22:34 UTC | |
by Anonymous Monk on Jun 06, 2009 at 01:16 UTC | |
by ikegami (Patriarch) on Jun 06, 2009 at 07:19 UTC | |
Re: IPC::Open3 misbehaving when STDOUT is not FD #1
by Khen1950fx (Canon) on Jun 07, 2009 at 00:43 UTC | |
Re: IPC::Open3 misbehaving when STDOUT is not FD #1
by Khen1950fx (Canon) on Jun 05, 2009 at 20:35 UTC | |
by sgifford (Prior) on Jun 05, 2009 at 22:11 UTC | |
by ikegami (Patriarch) on Jun 05, 2009 at 20:46 UTC |
Back to
Seekers of Perl Wisdom