in reply to Win32 Perl: inheriting redirected STDIN and STDOUT in a child process

While I'm not really advocating that you outright use IPC::Run, maybe you can use the techniques employed by it to do its task? It doesn't allow for interactivity, but for displaying the output, I'd redirect the output to a file and then use File::Tail in the parent process to read the output. If you want "real", select()-interactivity, using a named pipe (\\.\pipe\mypipe) or a network socket would be my approach.

  • Comment on Re: Win32 Perl: inheriting redirected STDIN and STDOUT in a child process
  • Download Code

Replies are listed 'Best First'.
Re^2: Win32 Perl: inheriting redirected STDIN and STDOUT in a child process
by BrowserUk (Patriarch) on Oct 22, 2008 at 18:18 UTC

      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        

        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