#! perl -slw use strict; use threads; use threads::shared; our $N //= 12; our $I //= 0; my $cmd = qq[$^X -E"\$|++; sleep $N; print 'Kid got ', scalar if $I; sleep 2;say 'Kid done'"]; my $timeout = time() + 10; my $inInputState :shared = 0; my $pid = open CMD, '|-', $cmd or die $!; my $old = select CMD; $|++; select $old; my $timedOut = 0; async { $inInputState = 1 if printf CMD " \b"x2048; }->detach; Win32::Sleep 10 until !kill 0, $pid or $timedOut = time() > $timeout or $inInputState ; if( $timedOut ) { print "Command timed out"; kill 3, $pid; } if( $inInputState ) { print "Child waiting for input"; print CMD 'hello'; } else { print "Kid never entered input state"; } print 'Parent done';