develooper Front page | perl.perl5.porters | Postings from June 2008

RE: Win32 exit values (was: Generic system() replacements)

Thread Previous | Thread Next
From:
Jan Dubois
Date:
June 17, 2008 23:09
Subject:
RE: Win32 exit values (was: Generic system() replacements)
Message ID:
0a3401c8d109$db147140$913d53c0$@com
On Tue, 17 Jun 2008, Paul Fenwick wrote:
> > On Windows the full exit status is actually a signed 32-bit integer,
> 
> Just doing some testing with this statement.  I can't seem to convince
> *perl* that it can return a 32-bit integer:
> 
> 	C:\> perl -e"exit 10_000"
> 	C:\> echo %errorlevel%
> 	10000
> 
> 	C:\> perl -e"exit 100_000"
> 	C:\> echo %errorlevel%
> 	34464

That's because Perl explicitly truncates the exitvalue to 16 bits:

#   define STATUS_UNIX_SET(n)           \
        STMT_START {                    \
            PL_statusvalue = (n);               \
            if (PL_statusvalue != -1)   \
                PL_statusvalue &= 0xFFFF;       \
        } STMT_END

(this is being called in Perl_my_exit())

So for some really weird reason you can actually set an exit code of -1,
but are otherwise restricted to unsigned 16 bit values.

Here is a sample where the command is executed twice when the exit status is -1:

  perl -e "$!=2; system(q(perl -e \"warn;exit -1\"))"
  Warning: something's wrong at -e line 1.
  Warning: something's wrong at -e line 1.

Contrary to what I wrote earlier, the double-execution only happens when $! was
set to either ENOENT or ENOEXEC before invoking system().

I have sometimes thought about fixing this whole mess for Windows, but whenever
I look at all the exit code related macros for VMS in perl.h I get scared. :)

Maybe it is time to just ignore irrational fear and go ahead and just do it...

Cheers,
-Jan


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About