[automation/dotnet] - Fix child process stream capture (#6586)

This commit is contained in:
Josh Studt 2021-03-19 22:16:32 -04:00 committed by GitHub
parent dd53f58acb
commit 3ce5623270
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -101,10 +101,22 @@ namespace Pulumi.Automation.Commands
proc.Exited += (_, @event) =>
{
var code = proc.ExitCode;
// this seems odd, since the exit event has been triggered, but
// the exit event being triggered does not mean that the async
// output stream handlers have ran to completion. this method
// doesn't exit until they have, at which point we can be sure
// we have captured the output in its entirety.
// note that if we were to pass an explicit wait time to this
// method it would not wait for the stream handlers.
// see: https://github.com/dotnet/runtime/issues/18789
proc.WaitForExit();
var result = new CommandResult(code, standardOutputBuilder.ToString(), standardErrorBuilder.ToString());
if (code != 0)
var result = new CommandResult(
proc.ExitCode,
standardOutputBuilder.ToString(),
standardErrorBuilder.ToString());
if (proc.ExitCode != 0)
{
var ex = CommandException.CreateFromResult(result);
tcs.TrySetException(ex);