in reply to Re^2: Win32 Perl: inheriting redirected STDIN and STDOUT in a child process
in thread Win32 Perl: inheriting redirected STDIN and STDOUT in a child process

I was surprised to see Corion suggest named pipes since I don't believe that 4-arg select works on named pipes in Win32.

Yes, I'd try something like Win32::Socketpair (your capital "P" makes your link go astray). If the module doesn't work, there really isn't all that much code there so I'd be a bit surprised if the module itself has problems on Perl 5.8.6 but I'd be really surprised if it was difficult to fix the module or even roll your own replacement (all you need to do is create quite ordinary TCP sockets). If one runs into problems, one can also look at the code for Win32::Sel­ectablePip­e that still sits on my scratchpad that I was trying to get turned into a module very similar to Win32::Socketpair (except that it would know how to override pipe so that it could fix already-written code to make it work on Win32).

- tye        

  • Comment on Re^3: Win32 Perl: inheriting redirected STDIN and STDOUT in a child process (select)

Replies are listed 'Best First'.
Re^4: Win32 Perl: inheriting redirected STDIN and STDOUT in a child process (select)
by TGI (Parson) on Oct 23, 2008 at 16:32 UTC

    Win32::Socketpair did the trick. Apparently pipes aren't handled well when redirecting STDIO.

    The module does exactly the same thing to redirect the STDIN/STDOUT that I tried without success. The big difference was that it was using a network socket instead of a pipe.

    For the record, I did have to set the handles to autoflush in both the client and server code in order for things to work properly.

    Thanks for your help.

    # In the server: use IO::Handle; my @command = ( 'perl', 'client.pl' ); my ($started, $fd)= winopen2( @command ); $fd->autoflush; # and the client: use IO::Handle; STDIN->autoflush; STDOUT->autoflush; print "$_" while <>;


    TGI says moo

      I did have to set the handles to autoflush in both the client and server code in order for things to work properly.

      That sounds likely to fix the problems I saw when I tried it after salva first mentioned it here. I didn't have a specific use for it at the time, and didn't spend any time trying to work out why it wasn't working.

      Maybe you could suggest that salva mention autoflush in the POD. (Also, there are a couple of missing parens in the synopsis code that do not inspire confidence.)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.