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 .

In reply to Bug in Perl 5.04 with return value to shell from die, after using backticks or qx by Mungbeans

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.