Mungbeans has asked for the wisdom of the Perl Monks concerning the following question:
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...";
$ 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 | |
by Mungbeans (Pilgrim) on Mar 11, 2004 at 17:24 UTC | |
by Abigail-II (Bishop) on Mar 11, 2004 at 18:00 UTC |