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

If the program does run and produce normal output, the message might be due to an incorrect interpretation of its status/return code1.  Maybe some variation of the issue discussed in What error is "No Error", where the problem seems to have been a negative return code of the program in question.  What return code do you get when you run the same command interactively from the command line?

___

1  this is the respective snippet from Perl's win32.c where the warning (presumably) originates from:

if (status < 0) { if (ckWARN(WARN_EXEC)) Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't spawn \"%s\": %s +", argv[0], strerror(errno)); status = 255 * 256; }

Replies are listed 'Best First'.
Re^2: Can't spawn "cmd.exe":
by emalossi (Novice) on Mar 18, 2009 at 14:26 UTC
    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 !!

      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.

      "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)".
      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.