[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;
}
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);