In IPC::Open3::_open(), switch from 'r' and 'w' to '<' and '>'.
authorNicholas Clark <nick@ccl4.org>
Mon, 6 Jun 2011 17:48:03 +0000 (19:48 +0200)
committerNicholas Clark <nick@ccl4.org>
Sat, 11 Jun 2011 06:48:16 +0000 (08:48 +0200)
IO::Handle accepts either, but open only accepts the latter.

In spawn_with_handles(), hoist the C<require Fcntl> into the only block that
needs it - this avoids loading Fcntl on Win32.

ext/IPC-Open3/lib/IPC/Open3.pm

index c57a306..2560176 100644 (file)
@@ -214,9 +214,9 @@ sub _open3 {
        croak "$Me: $@";
     }
 
-    my @handles = ({ mode => 'r', handle => \*STDIN },
-                  { mode => 'w', handle => \*STDOUT },
-                  { mode => 'w', handle => \*STDERR },
+    my @handles = ({ mode => '<', handle => \*STDIN },
+                  { mode => '>', handle => \*STDOUT },
+                  { mode => '>', handle => \*STDERR },
                  );
 
     foreach (@handles) {
@@ -383,7 +383,6 @@ sub spawn_with_handles {
     my $fds = shift;           # Fields: handle, mode, open_as
     my $close_in_child = shift;
     my ($fd, $pid, @saved_fh, $saved, %saved, @errs);
-    require Fcntl;
 
     foreach $fd (@$fds) {
        $fd->{tmp_copy} = IO::Handle->new_from_fd($fd->{handle}, $fd->{mode});
@@ -400,6 +399,7 @@ sub spawn_with_handles {
                              $fd->{mode});
     }
     unless ($^O eq 'MSWin32') {
+       require Fcntl;
        # Stderr may be redirected below, so we save the err text:
        foreach $fd (@$close_in_child) {
            next unless fileno $fd;