jimw54321 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I have run into a strange situation. With this code,
#!/usr/bin/perl use warnings; use strict; use DBI; system( "true" ); print "\$?: $?\n"; my $dbh = DBI->connect ("dbi:Oracle:", 'username', 'password', {AutoCo +mmit => 0 }) or die "Unable to connect to the database: $DBI::errstr"; system( "true" ); print "\$?: $?\n"; exit 0;
I get
$?: 0 $?: -1

I read in perlvar about $? and SIGCHLD but do not really understand it. Am not having this problem on my test box.

My perl version in production is 5.8.0. DBI is 1.50. DBD:Oracle is 1.16.

My perl in test where i am not having the problem is also 5.8.0. DBI is 1.50. DBD::Oracle is 1.17.

Any help getting me to understand and work around this is appreciated.

Thanks PerlMonks

Replies are listed 'Best First'.
Re: connection to database interfering with $?
by mje (Curate) on Jan 15, 2014 at 17:26 UTC

    The Oracle client libraries can interfere with SIGCHLD depending on how you connect to Oracle. Search the dbi-users list for SIGCHLD and oracle and you'll find ways of connecting which avoid this. There is also a setting in later DBD::Oracle to restore signals after connect but your DBD::Oracle's are SOOO old you've no chance of using that facility.

Re: connection to database interfering with $?
by andal (Hermit) on Jan 16, 2014 at 09:25 UTC

    Read description of $? carefully. There it states that if SIGCHLD is set, then $? shall be incorrect. Check the following code

    system('true'); print "\$? is $?\n"; $SIG{CHLD} = 'IGNORE'; system('true'); print "\$? is $?\n";

    From this follows, that most likely your DBI call has set the $SIG{CHLD} and didn't clear it.

Re: connection to database interfering with $?
by Anonymous Monk on Jan 15, 2014 at 16:53 UTC

    use POSIX(); system( @cmd ); my $child_exit_status = POSIX::WEXITSTATUS($?);

    use System::Command; my @cmd = qw( true ); my $cmd = System::Command->new( @cmd ); $cmd->exit(); # exit status