#!perl -w use strict; use Win32::API; use Win32; use Win32API::File qw(FdGetOsFHandle); Win32::API->Import( 'kernel32', 'DuplicateHandle', 'NNNPNNN', 'N', ); Win32::API->Import( 'kernel32', 'OpenProcess', 'NNN', 'N', ); # This is the child process that reads the number from STDIN, opens that handle, and reads from it my $cmd = q(| perl -MWin32API::File=OsFHandleOpen -e "$fileno=0+<> or die;OsFHandleOpen(FH, $fileno,'r') or die $!; print for "); my $child = open my $child_fh, $cmd or die "Can't spawn child [$cmd]: $! / $? / $^E"; print "1..2\n"; print "1 "; print $child ? "" : "not "; print "ok # spawned child\n"; # 0x400 for PROCESS_QUERY_INFORMATION # 0x040 for PROCESS_DUP_HANDLE my $childHandle = OpenProcess(0x440,0,$child) or die $^E; my $buf = "\0\0\0\0"; my $fhandle = FdGetOsFHandle( fileno *DATA ); DuplicateHandle(-1, $fhandle, $childHandle, $buf, 0, 1, 3 ) or die $^E; $buf = unpack "V", $buf; # Now tell our child from what handle it should read print {$child_fh} "$buf\n"; # The parent is done close $child_fh; __DATA__ 2 ok # output read from child process