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

I'm having a problem with perl returning incorrect success flags back to the unix shell, after issuing a back tick or qx command, and then attempting to die.

This code should die with an error, and return a failure to the shell.

#!/usr/bin/perl -I/usr/local/dcvp/bin use strict; my $output = qx(asasas 2>&1); ### Non-existent system call to force e +rror #$? = 0; ### This fails correctly if we reset $? but reports success o +therwise die " *** THIS SHOULD FAIL *** "; print "At least we don't see this message...";

Unfortunately it doesn't, I get this output:
$ test3.pl && echo success sh: asasas: not found *** THIS SHOULD FAIL *** at test3.pl line 5. success

This is only a problem on 5.04, 5.05 and later is fine.

I'm curious if anyone had encountered this before because it's causing shell scripts that rely on die/croak reporting errors correctly to fail.

We can work around it by resetting $? to 0 immediately after the system call.

Upgrading would fix this but we have some old xs API's that may not re-compile correctly under the new version. I know that 5.04 is reported to be unstable on solaris so I would *like* to upgrade. However, upgrading the production box will take a lot of effort to convince the clients and system administrators, so if anyone knows of any compelling bugs that they can point me at, I'd be grateful.

I believe this may be a logged bug because it's such an old version of perl, but if no-one has heard of this I'll submit it.

The perl version details are:

perl -V Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration: Platform: osname=solaris, osvers=2.6, archname=sun4-solaris uname='sunos cairnpapple 5.6 generic sun4u sparc sunw,ultra-4 ' hint=recommended, useposix=true, d_sigaction=define bincompat3=y useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O', gccversion=2.7.2.3 cppflags='' ccflags ='' stdchar='unsigned char', d_stdstdio=define, usevfork=false voidflags=15, castflags=0, d_casti32=define, d_castneg=define intsize=4, alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='cc', ldflags ='' libpth=/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc -lcrypt libc=/lib/libc.so, so=so useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-fpic', lddlflags='-G' Characteristics of this binary (from libperl): Built under solaris Compiled at Dec 10 1998 12:51:04 @INC: /opt/gnu/lib/perl5/sun4-solaris/5.00404 /opt/gnu/lib/perl5 /opt/gnu/lib/perl5/site_perl/sun4-solaris /opt/gnu/lib/perl5/site_perl .

Replies are listed 'Best First'.
Re: Bug in Perl 5.04 with return value to shell from die, after using backticks or qx
by Abigail-II (Bishop) on Mar 11, 2004 at 17:15 UTC
    This is only a problem on 5.04, 5.05 and later is fine.
    Hmmm, then the solution seems to be obvious, doesn't it? Get rid of your more than 6 year old version of Perl, and install one of: 5.004_05 (if it fixes the problem), 5.005_04, 5.6.1 or 5.8.3.

    Abigail

      I'd like to upgrade but I need ammo. Given that the code is old and unstable should be enough, but we've got what I can politely describe as a "change averse environment".

      Still that is my problem of course...

        I'd like to upgrade but I need ammo.
        If "old version broken, new version works" doesn't do it, what does? If it's a matter of office politics, I'd rather not have those pointless discussions here.

        Abigail