diff --git a/base/shell/cmd/batch.c b/base/shell/cmd/batch.c index bf36ddb6100..148943a9904 100644 --- a/base/shell/cmd/batch.c +++ b/base/shell/cmd/batch.c @@ -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; diff --git a/base/shell/cmd/internal.c b/base/shell/cmd/internal.c index 4830660bbc8..fc05119829e 100644 --- a/base/shell/cmd/internal.c +++ b/base/shell/cmd/internal.c @@ -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; }