https://git.reactos.org/?p=reactos.git;a=commitdiff;h=56a19b1439effc8a3990f9...
commit 56a19b1439effc8a3990f97ff9241379d55a07cb Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sat Nov 18 20:50:50 2017 +0100
[CMD] ExecutePipeline() returns the last error level (set to process exit code). CORE-13974
This should fix situations where (for example): command_1 | command_2 && echo Succeeded should *NOT* run "echo Succeeded" if any of the command_1 or command_2 has failed.
This also makes the ExecutePipeline() function on par with the other "ExecuteXXX()" helpers.
Problem diagnosed by Doug Lyons; patch inspired by contributor 'cagey45'. --- base/shell/cmd/cmd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c index e6c9bec785..549f10d59e 100644 --- a/base/shell/cmd/cmd.c +++ b/base/shell/cmd/cmd.c @@ -636,7 +636,7 @@ ExecuteAsync(PARSED_COMMAND *Cmd) return prci.hProcess; }
-static VOID +static INT ExecutePipeline(PARSED_COMMAND *Cmd) { #ifdef FEATURE_REDIRECTION @@ -708,7 +708,7 @@ ExecutePipeline(PARSED_COMMAND *Cmd)
while (--nProcesses >= 0) CloseHandle(hProcess[nProcesses]); - return; + return nErrorLevel;
failed: if (hInput) @@ -721,6 +721,8 @@ failed: SetStdHandle(STD_INPUT_HANDLE, hOldConIn); SetStdHandle(STD_OUTPUT_HANDLE, hOldConOut); #endif + + return nErrorLevel; }
INT @@ -771,7 +773,7 @@ ExecuteCommand(PARSED_COMMAND *Cmd) Ret = ExecuteCommand(Sub->Next); break; case C_PIPE: - ExecutePipeline(Cmd); + Ret = ExecutePipeline(Cmd); break; case C_IF: Ret = ExecuteIf(Cmd);