diff --git a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs index 62e1eb594..570b5accb 100644 --- a/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs +++ b/src/SourceBuild/tarball/content/test/Microsoft.DotNet.SourceBuild.SmokeTests/ExecuteHelper.cs @@ -75,16 +75,30 @@ internal static class ExecuteHelper process.WaitForExit(); } - string output = stdOutput.ToString().Trim(); - if (logOutput && !string.IsNullOrWhiteSpace(output)) + string output; + string error; + + lock (stdOutput) { - outputHelper.WriteLine(output); + output = stdOutput.ToString().Trim(); } - string error = stdError.ToString().Trim(); - if (logOutput && !string.IsNullOrWhiteSpace(error)) + lock (stdError) { - outputHelper.WriteLine(error); + error = stdError.ToString().Trim(); + } + + if (logOutput) + { + if (!string.IsNullOrWhiteSpace(output)) + { + outputHelper.WriteLine(output); + } + + if (string.IsNullOrWhiteSpace(error)) + { + outputHelper.WriteLine(error); + } } return (process, output, error);