IPC::Open3

E

ed

is it possible to get the exit status of a program that is started using
IPC::Open3?

#!/usr/bin/perl

use strict;
use warnings;
use IPC::Open3;

my $bpid = open3( my $bwr, my $brd, my $ber, "ls -al /fdsfsdfsfs" );
close($bwr);
close($brd);
print( $? );


this should close with exit 2 on my system, but i cannot seem to capture
the exit code at all.
 
C

Charles DeRykus

ed said:
is it possible to get the exit status of a program that is started using
IPC::Open3?

#!/usr/bin/perl

use strict;
use warnings;
use IPC::Open3;

my $bpid = open3( my $bwr, my $brd, my $ber, "ls -al /fdsfsdfsfs" );
close($bwr);
close($brd);
print( $? );


this should close with exit 2 on my system, but i cannot seem to capture
the exit code at all.

The best examples for IPC::Open3 are found here in my opinion:
perldoc -q external

In your sample case, backticks would be more straightforward.

But, a possible solution with Open3:

$bpid = open3( ... )
waitpid( $bpid, 0 );
warn "exit code = ", $?>>8, "\n";

or, if you wanted to capture any error text too:

open( my $ber, '<&2' ) or die $!;
$bpid = open3(... );
waitpid ( $bpid, 0 );
if ($?) {
warn "exit code = ", $?>>8, "\n";
warn "error status = ", <$ber>;
}
 
X

xhoster

ed said:
is it possible to get the exit status of a program that is started using
IPC::Open3?

#!/usr/bin/perl

use strict;
use warnings;
use IPC::Open3;

my $bpid = open3( my $bwr, my $brd, my $ber, "ls -al /fdsfsdfsfs" );
close($bwr);
close($brd);
print( $? );

this should close with exit 2 on my system, but i cannot seem to capture
the exit code at all.

from the IPC::Open3 doc:

open3() does not wait for and reap the child process after
it exits. Except for short programs where it's acceptable
to let the operating system take care of this, you need to
do this yourself. This is normally as simple as calling
"waitpid $pid, 0" when you're done with the process.

waitpid will set $?.


Xho
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top