View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
BrowserUk > Win32-Socketpair-0.02 > Win32::Socketpair



Annotate this POD


New  3
Open  1
View/Report Bugs
Module Version: 0.02   Source  


Win32::Socketpair - Simulate socketpair on Windows


  use Win32::Socketpair 'winopen2';

  my $socket = winopen2(@cmd);

  my $fn = fileno $socket;
  my $v = '';
  vec($v, $fn, 1) = 1;

  while (1) {
    if (select(my $vin = $v, my $vout = $v, undef, undef) > 0) {
      if (vec($vout, $fn, 1) {
        syswrite($socket, "hello\n") or last;
      if (vec($vin, $fn, 1) {
        sysread($socket, my $buffer, 2048) or last;
        print "read: $buffer";


This module allows to create a bidirectional pipe on Windows that can be used inside a select loop. It uses a TCP socket going through the localhost interface to create the connection.

Also export winopen2() (and winopen2_5()) which use the socketpair to perform a bidirection "piped open" allowing writing to the subprocess' stdin and copturing it stdout (and stderr).


The subroutines that can be imported from this module are:

($fd1, $fd2) = winsocketpair()

creates a socket connection through the localhost interface.

It returns a pair of file descriptors representing both sides of the socket.

($pid, $fd1) = winopen2(@cmd)

creates a socket connection through the localhost interface and launchs the external command @cmd on the background using one side of the socket as its STDIN and STDOUT.

It returns the pid of the new process and the file descriptor for the other side of the socket or an empty list on failure.

($pid, $fd1) = winopen2_5(@cmd)

As above, but also captures stderr as well as stdout. Effectively the same as doing 2>&1, but avoiding the shell.


IPC::Open2, perlipc, perlfunc.


Copyright (C) 2006 Salvador Fandiño <>. Copyright (C) 2012 by BrowserUk <>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: