[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'.
This commit is contained in:
Hermès Bélusca-Maïto 2017-11-18 20:50:50 +01:00
parent 0701527f20
commit 56a19b1439
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -636,7 +636,7 @@ ExecuteAsync(PARSED_COMMAND *Cmd)
return prci.hProcess; return prci.hProcess;
} }
static VOID static INT
ExecutePipeline(PARSED_COMMAND *Cmd) ExecutePipeline(PARSED_COMMAND *Cmd)
{ {
#ifdef FEATURE_REDIRECTION #ifdef FEATURE_REDIRECTION
@ -708,7 +708,7 @@ ExecutePipeline(PARSED_COMMAND *Cmd)
while (--nProcesses >= 0) while (--nProcesses >= 0)
CloseHandle(hProcess[nProcesses]); CloseHandle(hProcess[nProcesses]);
return; return nErrorLevel;
failed: failed:
if (hInput) if (hInput)
@ -721,6 +721,8 @@ failed:
SetStdHandle(STD_INPUT_HANDLE, hOldConIn); SetStdHandle(STD_INPUT_HANDLE, hOldConIn);
SetStdHandle(STD_OUTPUT_HANDLE, hOldConOut); SetStdHandle(STD_OUTPUT_HANDLE, hOldConOut);
#endif #endif
return nErrorLevel;
} }
INT INT
@ -771,7 +773,7 @@ ExecuteCommand(PARSED_COMMAND *Cmd)
Ret = ExecuteCommand(Sub->Next); Ret = ExecuteCommand(Sub->Next);
break; break;
case C_PIPE: case C_PIPE:
ExecutePipeline(Cmd); Ret = ExecutePipeline(Cmd);
break; break;
case C_IF: case C_IF:
Ret = ExecuteIf(Cmd); Ret = ExecuteIf(Cmd);