Warning message: Can't spawn ... No error



I have the following perl program to test return codes (I am running
Strawberry Perl 5.12 under Windows Vista 64 bits):

use 5.012;
use warnings;

say 'Start';
system qq{perl -e"exit -1"};
say 'Stop';

Here is the output:
Can't spawn "perl -e"exit -1"": No error at C:\test.pl line 5.

The program as such runs ok, but the problem is the warning messageat all. I want to have warnings on in general, but this particular
warning is not desired. Why should there be a warning at all if the
return code is negative ? -- If I run the same program with "...exit
1;..." then everything is ok, i.e. no warning is emitted.

In the real world scenario, I have an *.exe file that occasionally
emits negative return codes, in which case a >>Can't spawn...No
error<< warning message is emitted. I can't change the behaviour of
the *.exe file. How can I get rid of this particular warning message ?
-- I could say no warnings in the lexical scope of the system command,
but I find this message is completely useless.

I wonder what my fellow perl programmers think about this warning


You can turn this particular warning (and a few others) off with no
warnings "exec". You will see an apparent exit value of 255, regardless
of what the program actually exitted with, though you should see the
real exitcode in ${^CHILD_ERROR_NATIVE}.

I wasn't aware negative exit codes were possible. They aren't on Unix:
the exit code section of the value returned by wait(2) is an unsigned
8-bit integer, so attempting to call exit(-1) will lead to the parent
seeing an exit code of 255.

Win32's native exit status is a DWORD. I believe DWORD is an unsigned
type, which would mean this section of win32_spawnvp:

        DWORD status;
        win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
        /* FIXME: if msgwait returned due to message perhaps forward the
           "signal" to the process
        GetExitCodeProcess(ProcessInformation.hProcess, &status);
        ret = (int)status;

is wrong, since it's casting a DWORD to a signed integer, and the caller
is assuming a negative return means an error. It should probably be
followed by something like

    if (ret < 0) ret = PERL_MAX_INT;

or maybe just replaced with

    ret = status > PERL_MAX_INT ? PERL_MAX_INT : (int)status;

And somewhat confusingly, backticks don't generate a

perl -wlE "say 'Start'; qx{$^X -e \"system exit -1\"};
say 'Stop: ',$?>>8"
Stop: 255

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Latest member

Latest Threads