mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[CMD] Fix the errorlevel value set by the EXIT command, and when a batch file has run.
CORE-10495 CORE-13672 - Fix the behaviour of the EXIT command, where it set the last errorlevel value ONLY when it was called with the /b switch and otherwise kept the ambient one, instead of always using the value that the user specified on the command-line. - When a batch file has terminated, make the Batch() helper returning the errorlevel value so that, when the batch file has been started with the CALL command, CALL can in turn set the correct errorlevel value. Verified with respect to Windows' cmd.exe.
This commit is contained in:
parent
24ed534474
commit
26ff2c8ef3
2 changed files with 26 additions and 9 deletions
|
@ -299,7 +299,8 @@ INT Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
|||
* return until this context has been exited */
|
||||
new.prev = bc;
|
||||
/* copy some fields in the new structure if it is the same file */
|
||||
if (same_fn) {
|
||||
if (same_fn)
|
||||
{
|
||||
new.mem = bc->mem;
|
||||
new.memsize = bc->memsize;
|
||||
new.mempos = 0;
|
||||
|
@ -366,6 +367,9 @@ INT Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
|
|||
FreeCommand(Cmd);
|
||||
}
|
||||
|
||||
/* Always return the current errorlevel */
|
||||
ret = nErrorLevel;
|
||||
|
||||
TRACE ("Batch: returns TRUE\n");
|
||||
|
||||
fc = saved_fc;
|
||||
|
|
|
@ -514,26 +514,39 @@ INT CommandExit(LPTSTR param)
|
|||
if (!_tcsncmp(param, _T("/?"), 2))
|
||||
{
|
||||
ConOutResPaging(TRUE, STRING_EXIT_HELP);
|
||||
/* Just make sure */
|
||||
|
||||
/* Just make sure we don't exit */
|
||||
bExit = FALSE;
|
||||
/* Don't exit */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bc != NULL && _tcsnicmp(param, _T("/b"), 2) == 0)
|
||||
if (_tcsnicmp(param, _T("/b"), 2) == 0)
|
||||
{
|
||||
param += 2;
|
||||
while (_istspace(*param))
|
||||
param++;
|
||||
if (_istdigit(*param))
|
||||
nErrorLevel = _ttoi(param);
|
||||
ExitBatch();
|
||||
|
||||
/*
|
||||
* If a current batch file is running, exit it,
|
||||
* otherwise exit this command interpreter instance.
|
||||
*/
|
||||
if (bc)
|
||||
ExitBatch();
|
||||
else
|
||||
bExit = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Exit this command interpreter instance */
|
||||
bExit = TRUE;
|
||||
}
|
||||
|
||||
/* Search for an optional exit code */
|
||||
while (_istspace(*param))
|
||||
param++;
|
||||
|
||||
/* Set the errorlevel to the exit code */
|
||||
if (_istdigit(*param))
|
||||
nErrorLevel = _ttoi(param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue