UGH, what an ugly POS (piece of software). And it spews stderr into your terminal, instead of providing some control over it). And you can't test the darn thing interactively.
Suppose your process gets killed, e.g. run this and pkill sleep:
my $ls = 'sleep 1000';
open( LS, "$ls |" );
while ( ){
print "OUTPUT $_";
}
close LS;
print "EXIT $? \n"
All you get from the above is pitiful, grossly inadequate:
EXIT 15
Now try this in Tcl:
set pipe [open "| sleep 1000"]
while {[gets $pipe line] >= 0} {puts "OUT $line"}
if {[catch {close $pipe} msgFromStderr]} then {
puts $msgFromStderr
puts "Process [lindex $errorCode 1] exited with status [lindex $errorCode 2] (code [lindex $errorCode 0])"
} else {
puts "Exit code 0"
}
and pkill sleep again. You get a nice, informative message:
child killed: software termination signal
Process 19144 exited with status SIGTERM (code CHILDKILLED)
KK