## Start the command connecting our output to its input ## (You might need to use open2/3() if you want to capture the output) my $pid = open CMD, '|-', $cmd or die $!; ## A shared var that captures whether the print succeeds ## If it does, the process went into an input state ## if it doesn't it ended (or was terminated) without entering an input state my $inInputState :shared = 0; ## Attempt to write to the process ## in a thread so we can do other things while it blocks. ## No newline so the process doesn't see it ## a series of spaces followed by backspaces ## which should be "cancelled out" by the line edit API ## 4096 chars to ensure it gets through pipe buffering async { $inInputState = 1 if printf CMD " \b"x2048; }->detach; ## A microsleep to ensure responsiveness whilst avoiding cpu burn ## until the process self terminates ## or we reach the timeout period ## or the print succeeds -- entered input state Win32::Sleep 10 until !kill 0, $pid or $timedOut = time() > $timeout or $inInputState