sdk: Dotnet run does not preserve colors in child processes
@mattwarren in BenchmarkDotNet brought this to my attention
Steps to reproduce
dotnet new
make Program.cs
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Hello World!");
}
}
}
dotnet restore
dotnet run
Expected behavior
Outputs gray text
Actual behavior
Environment data
dotnet --version output:
C:\Users\brthor\code\repro\run-color>dotnet --version
.NET Command Line Tools (1.0.0-beta-001828)
Product Information:
Version: 1.0.0-beta-001828
Commit Sha: N/A
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
Runtime Id: win10-x64
I’d expect this to be present anywhere because we don’t do anything special to handle Console.SetColor or Console.ForegroundColor calls in child processes.
cc @anurse any ideas on how we could handle this?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 42 (35 by maintainers)
Has this fix been released? I’m still seeing uncolored output when using
dotnet watch.This is a problem, it seems, with all things that wrap
dotnet run, likedotnet testanddotnet watch.I am seeing this even today with 1.0.0-preview2-003119. That’s pretty new. We need to fix this soon IMHO, it’s super annoying. @Eilon
We call
ForwardStdOuton the command we launch. We shouldn’t. It’s basically that simple 😃. Then the colors should flow properly on Windows.@brthor in https://github.com/dotnet/cli/issues/1977#issuecomment-227214885 @shanselman is talking about
dotnet watchanddotnet testnotdotnet runhaving this issue. So @BrennanConroy codepath is being hit.Thanks, @miniksa. That’s helpful. And in that case it sounds like at present there’s no action item for System.Console.dll in corefx.
Which brings us back to @shanselman’s list of issues:
As @BrennanConroy suggested, sounds like this is just a matter of removing some calls to ForwardStdOut, and this issue could be used to track that happening.
Sounds like a different issue should be used to track that.
Sounds like a different issue should be used to track that.
Nothing here for corefx. Potentially some kind of work item for dotnet if these issues aren’t addressed by simply removing the superfluous ForwardStdOut calls.
@livarcocc It isn’t dotnet run that causes the issue, its the
command.Create(...).ForwardStdOut().ForwardStdErr();that calls AnsiConsole which causes the issue@piotrpMSFT @Petermarcu can we have someone look at this? It’s quite difficult to read the un-colorized output when using
dotnet run(or similar). It seems the fix is as easy as not piping the sub-command’s output. The piping breaks streaming the data “live” as well as breaks any console commands that don’t go out on the stream, such as setting the current console colors.cc @DamianEdwards