[CMD] Additional fixes for ERRORLEVEL and last returned exit code from EXIT, CALL commands and CMD.

CORE-10495 CORE-13672

- Fix how the ERRORLEVEL and the last returned exit code are set by
  EXIT and CALL commands, when batch contexts terminate, and when CMD
  runs in single-command mode (with /C).

  Addendum to commit 26ff2c8e, and reverts commit 7bd33ac4.
  See also commit 8cf11060 (r40474).

  More information can be found at:
  https://ss64.com/nt/exit.html
  https://stackoverflow.com/a/34987886/13530036
  https://stackoverflow.com/a/34937706/13530036

- Move the actual execution of the CMD command-line (in /C or /K
  single-command mode) from Initialize() to _tmain(), to put it on par
  with the ProcessInput() interactive mode.

- Make ProcessInput() also return the last command's exit code.
This commit is contained in:
Hermès Bélusca-Maïto 2020-07-30 01:44:43 +02:00
parent 4c9d322c68
commit d78e8029b8
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 68 additions and 40 deletions

View file

@ -548,13 +548,16 @@ INT CommandExit(LPTSTR param)
/* Search for an optional exit code */
while (_istspace(*param))
param++;
++param;
/* Set the errorlevel to the exit code */
if (_istdigit(*param))
{
nErrorLevel = _ttoi(param);
// if (fSingleCommand == 1) return nErrorLevel;
}
return 0;
return (bExit ? nErrorLevel : 0);
}
#ifdef INCLUDE_CMD_REM