Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ async ValueTask<int> RunDotnetAsync(
};

var callCounts = new ProcessCallbackCallCounts();
var stdoutBuffer = new List<string>();
var stdoutLock = new object();

proc.ErrorDataReceived += (sender, args) =>
{
Expand All @@ -465,17 +467,27 @@ async ValueTask<int> RunDotnetAsync(
}
};

if (requireStdOutLogging)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If stdout is redirected, simply, write log to both stdout and stderr without any consideration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated RunDotnetAsync to always log to both stdout and stderr when redirection is active, regardless of requireStdOutLogging or content (errors/warnings), and removed the redundant buffer dump for this case.

proc.OutputDataReceived += (sender, args) =>
{
proc.OutputDataReceived += (sender, args) =>
if (args.Data != null)
{
if (args.Data != null)
lock (stdoutLock)
{
stdoutBuffer.Add(args.Data);
}

if (requireStdOutLogging || Console.IsOutputRedirected)
{
Interlocked.Increment(ref callCounts.Stdout);
Console.WriteLine(Colorize(args.Data)); // DO NOT use ConsoleLogger here!
var colorized = Colorize(args.Data);
Console.WriteLine(colorized); // DO NOT use ConsoleLogger here!
if (Console.IsOutputRedirected)
{
Console.Error.WriteLine(colorized);
}
}
};
}
}
};

if (!proc.Start())
{
Expand All @@ -491,6 +503,22 @@ async ValueTask<int> RunDotnetAsync(

await proc.WaitForExitAsync();

if (proc.ExitCode != 0 && !requireStdOutLogging && !Console.IsOutputRedirected)
{
lock (stdoutLock)
{
foreach (var line in stdoutBuffer)
{
var colorized = Colorize(line);
Console.Error.WriteLine(colorized);
if (ConsoleLogger.EnableMarkdownOutput)
{
Console.WriteLine(colorized);
}
}
}
}

if (ConsoleLogger.EnableMarkdownOutput)
{
if (requireDetailsTag)
Expand Down
Loading