open, ipc, and return codes

G

gary

Hi,

Is there a way to get the return code from the child process that was started with open?

open(STATUS, "mycommand |") || die "can't fork: $!";
while (<STATUS>) {
bla;
}
close STATUS || die "bad mycommand: $! $?";

but what I need is the return code from "mycommand" itself. Is there a way to do this?

thanks,
gary
 
S

Steve Grazzini

gary said:
Is there a way to get the return code from the child process
that was started with open?

close STATUS || die "bad mycommand: $! $?";

That's not quite right. (Precedence problem.)

close(STATUS) or die "command failed: $! $?";
but what I need is the return code from "mycommand" itself. Is
there a way to do this?

If the exit status is nonzero, close() will return undef and the
wait() status is in $?.
 
S

Steve Grazzini

gary said:
If that example is wrong then the perldoc is wrong!

Hmm.

It's not really wrong as in "broken", but wrong as in "apt to confuse".
It confused me -- the proper rule is: built-in functions that take one
argument have the highest precedence, while other built-ins fall somewhere
in between "||" (relatively high precedence) and "or" (relatively low).

print $text || die $!; # doesn't work
close FH || die $!; # does work

Sorry for the mix-up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top