From 56a19b1439effc8a3990f97ff9241379d55a07cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 18 Nov 2017 20:50:50 +0100 Subject: [PATCH] [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 e6c9bec785a..549f10d59ea 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);