in reply to Re: Can't spawn "cmd.exe":
in thread Can't spawn "cmd.exe":

almut, I think you've hit the nail. I ran this manually from the CLI and then did echo %ERRORLEVEL% and the value returned was -1. Is this the proper way to check this? I wonder if you could remind me, in windows what would be the "normal" return code, 0 or 1?

That's a very strange error message to return in the event of a negative return code. Not just meaningless but confusing as well. Is the reason why it is seen when run from perl but not when run directly in the CLI because cmd doesn't pass warnings, but perl does? Thanks !!

Replies are listed 'Best First'.
Re^3: Can't spawn "cmd.exe":
by ikegami (Patriarch) on Mar 18, 2009 at 15:32 UTC

    in windows what would be the "normal" return code, 0 or 1?

    0 for success, like unix.

    then did echo %ERRORLEVEL% and the value returned was -1.

    That's weird. Error codes are unsigned in Win32. IF ERRORLEVEL even relies on that.

    @echo off program.exe if errorlevel 3 goto ERROR if errorlevel 1 goto WARNING rem 0 <= errorlevel < 1 echo Success goto END :WARNING rem 1 <= errorlevel < 3 echo Warning goto END :ERROR rem 3 <= errorlevel echo Error :END

    That's a very strange error message to return in the event of a negative return code.

    No, the message is correct for a negative code being returned from the function that implements system. The problem is that the function is returning negative when the child was successfully launched.

    In Win32, exit codes are unsigned 32 bit values. Perl treats it as a signed 32-bit value.

    DWORD status; ... GetExitCodeProcess(ProcessInformation.hProcess, &status); ret = (int)status;

    The second line is a bug. Sufficiently high exit codes will be converted to negative. Negatives are used to signal a problem launching the process.

Re^3: Can't spawn "cmd.exe":
by runrig (Abbot) on Mar 18, 2009 at 15:23 UTC
    "Normal" return code seems to be zero. E.g., do a "dir" and then echo %ERRORLEVEL%. Now do "dir file_that_doesnt_exist" and echo %ERRORLEVEL% again. Now do " perl -e exit(-1)".
Re^3: Can't spawn "cmd.exe":
by almut (Canon) on Mar 18, 2009 at 15:51 UTC
    echo %ERRORLEVEL% ... Is this the proper way to check this?

    Yes, I think so, but I'm no Windows expert...

    As to the negative return code, IIRC, I was able to reproduce the issue last time with a self-compiled perl-5.8.8 on a Win XP (32-bit) vmware image. Unfortunately, I don't have access to that image at the moment, and any attempts to reproduce the problem on the Windows box I currently have access to (XP x64 SP2, with ActiveState's Perl 5.8.8) have failed so far...

    Maybe I'll continue to play with this later. In case I should dig up something of interest, I'll report back.