when perl execute line my $pid = open CMD, 'program.exe |' or die $!;. program.exe will run forever and my perl script hang.
The only way I'm aware of that can happen is if the program produces output without any newlines.
E.g: This (with -l so print adds newlines), returns control to the calling program immediately:
$pid = open CMD, '-|', q[perl.exe -le"print ++$i while sleep 1"] or di +e $!;;
But this (no newlines) won't return control to the caller until it fills and flushes the 4k buffer on STDOUT. Which given it only produces just a few characters every second, will take a long time:
$pid = open CMD, '-|', q[perl.exe -e"print ++$i while sleep 1"] or die + $!;;
If the program in question is buffering its output, is not adding newlines, and doesn't produce enough to fill the buffer, it will never return control to the caller.
In that case, you're pretty much screwed unless you can recompile the program.
In reply to Re^3: Run and Stop another program in perl
by BrowserUk
in thread Run and Stop another program in perl
by fast
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |