in reply to IPC::Open3 misbehaving when STDOUT is not FD #1

Simpler, clearer, more self-contained test:

#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Test::More tests => 1; # Hide undesired output. open(STDOUT, '>', '/dev/nul'); open(STDERR, '>', '/dev/nul'); # Associate STDOUT and STDERR with # descriptors other than 1 and 2. open(local *STDOUT, '>', '/dev/nul'); open(local *STDERR, '>', '/dev/nul'); open3( undef, local *PIPE, undef, 'echo out ; echo err >&2', ); my $pipe = ''; $pipe .= $_ while <PIPE>; is($pipe, "out\nerr\n");

Still unix-specific, though.

Replies are listed 'Best First'.
Re^2: IPC::Open3 misbehaving when STDOUT is not FD #1
by Anonymous Monk on Jun 06, 2009 at 01:16 UTC
    Portable?
    #!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Test::More tests => 1; use File::Spec; my $devnull = File::Spec->devnull; # Hide undesired output. open(STDOUT, '>', $devnull); open(STDERR, '>', $devnull); # Associate STDOUT and STDERR with # descriptors other than 1 and 2. open(local *STDOUT, '>', $devnull); open(local *STDERR, '>', $devnull); open3( undef, local *PIPE, undef, qq!$^X -le "print 111;print STDERR 222"!, ); my $pipe = ''; $pipe .= $_ while <PIPE>; is($pipe, "111\n222\n"); __END__
      $^X isn't properly converted to a shell literal. (i.e. Won't work if there's a space in $^X.) Fix:
      open3( undef, local *PIPE, undef, $^X, q!-le print 111;print STDERR 222!, );