#! perl -slw use strict; use threads; use Thread::Queue; sub pipeCommand { my $cmd = shift; my $Q = new Thread::Queue; async{ my $pid = open my $pipe, $cmd or die $!; $Q->enqueue( $_ ) while <$pipe>; $Q->enqueue( undef ); }->detach; return $Q; } my $pipe = pipeCommand( 'perl -le"$|++;print localtime().q[: some text] and sleep 1 for 1 .. 10" |' ) or die; while( 1 ) { if( $pipe->pending ) { my $line = $pipe->dequeue or last; chomp( $line ); ## Do stuff with $line printf "Got: '%s'\n", $line; } else { ## Do something else print 'Tum te tum'; Win32::Sleep 500; } } __END__ C:\test>621058-t Tum te tum Got: 'Thu Jun 14 01:43:13 2007: some text' Tum te tum Got: 'Thu Jun 14 01:43:14 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:15 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:16 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:17 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:18 2007: some text' Tum te tum Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:19 2007: some text' Tum te tum Got: 'Thu Jun 14 01:43:20 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:21 2007: some text' Tum te tum Tum te tum Got: 'Thu Jun 14 01:43:22 2007: some text' Tum te tum Tum te tum #### #! perl -slw use strict; use Win32API::File qw[ GetOsFHandle ]; use Win32::API::Prototype; ApiLink( 'Kernel32', q[ BOOL PeekNamedPipe( HANDLE hNamedPipe, LPVOID lpBuffer, DWORD nBufferSize, LPDWORD lpBytesRead, DWORD *lpTotalBytesAvail, LPDWORD lpBytesLeftThisMessage ) ] ) or die $^E; my $cmd = 'perl -le"$|++;print localtime().q[: some text] and sleep 1 for 1..10" |'; my $pid = open my $pipe, $cmd or die $!; warn $pid; my $pHandle = GetOsFHandle( $pipe ); warn $pHandle; while( 1 ) { my $cAvail = 0; if( ( PeekNamedPipe( $pHandle, 0, 0, 0, $cAvail, 0 ) or warn $^E ) and $cAvail ) { defined( my $line = <$pipe> ) or last; chomp( $line ); ## Do stuff with $line printf "Got: '%s'\n", $line; } else { ## Do something else print 'Tum te tum'; Win32::Sleep 500; } }