in reply to How to know the status of a command invoked by open function?

Just depends which command you want the exit status of. It’s quite easy with just one command, as others have shown you, and it’s only slightly trickier with getting the exit status from a command in a pipeline that isn’t the last such command.

For example, this runs dd to get some output while filtering out some stuff you don’t want with egrep, yet still manages to give you the dd exit status instead of the egrep one:

$dd_command = <<'EO_COMMAND'; device=/dev/rmt8 dd_noise='^[0-9]+\+[0-9]+ records (in|out)$' exec 3>&1 status=`((dd if=$device ibs=64k 2>&1 1>&3 3>&- 4>&-; echo $? >&4) | egrep -v "$dd_noise" 1>&2 3>&- 4>&-) 4>&1` exit $status; EO_COMMAND @dd_output = `$dd_command`; $status = ($? >> 8); $signo = ($? & 127); $cored = ($? & 128);

Of course the problem there is you can’t read as you go, so to do that via a pipe, do this:

$dd_command = <<'EO_COMMAND'; device=/dev/rmt8 dd_noise='^[0-9]+\+[0-9]+ records (in|out)$' exec 3>&1 status=`((dd if=$device ibs=64k 2>&1 1>&3 3>&- 4>&-; echo $? >&4) | egrep -v "$dd_noise" 1>&2 3>&- 4>&-) 4>&1` exit $status; EO_COMMAND $kidpid = open(DD_PIPE, "$dd_command |") // die $!; while (<DD_PIPE>) { # blah blah blah; } close(DD_PIPE); $status = ($? >> 8); $signo = ($? & 127); $cored = ($? & 128);
If those weren’t obvious, this is simpler:
$kidpid = open(FROM_KID, "somecmd 3>&1 1>&2 2>&3 3>&- |") // die $!;
The status//signo/cored bits will be the same, but this lets you concentrate on your three‐ball juggle. The short story is that’s more clearly read as:
$fd3 = $fd1; $fd1 = $fd2; $fd2 = $fd3; $fd3 = undef;
Now to use that knowledge in the earlier examples, just throw a fourth ball up into the air.

Easy as pi!

//GO.SYSIN DD *, DOODAH, DOODAH