Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird progress indicators started appearing in stdout #44610

Open
martinstenhoff opened this issue Nov 3, 2024 · 7 comments
Open

Weird progress indicators started appearing in stdout #44610

martinstenhoff opened this issue Nov 3, 2024 · 7 comments
Assignees
Labels
Area-CLI untriaged Request triage from a team member

Comments

@martinstenhoff
Copy link

martinstenhoff commented Nov 3, 2024

Why have I started seeing the following character sequence (which seems to some progress indicator) whenever I pipe dotnet program output to a file now?

\x1b]9;4;3;\x1b\\\x1b]9;4;0;\x1b\\

Program.cs:

Console.WriteLine("Hello, World!");

dotnet run > output.txt

output.txt:

�]9;4;3;�\�]9;4;0;�\Hello, World!
❯ dotnet --version
9.0.100-rc.2.24474.11
Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Nov 3, 2024
@martinstenhoff
Copy link
Author

This issue talks about some new console logger in .Net9
dotnet/msbuild#9950

I still see these characters in the output file if build and run are done in separate steps:

dotnet build -c Release
dotnet run -c Release --no-build -v q > .\output.txt

And it happens in both Command Prompt and Powershell terminal

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Nov 4, 2024

This seems to be coming from how dotnet run calls MSBuild to run the ComputeRunArguments target; output.txt sometimes includes "ComputeRunArguments (0,0s)".

$ cat -A output.txt
^[]9;4;3;^[\^[[?25l^[[1F^M$
  conc ^[[120G^[[26DComputeRunArguments (0,0s)^M$
^[[?25h^[[2F^M$
^[[J^[]9;4;0;^[\Hello, World!^M$

But surprisingly, setting MSBUILDTERMINALLOGGER=off in the environment or adding -terminalLogger:off to the dotnet run command line does not remove these.

Actually, dotnet run explicitly instantiates the terminal logger instead of letting MSBuild check whether the -terminalLogger option was specified, whether the environment variable was set, and whether output was redirected:

// if the restoreArgs contain a `-bl` then let's probe it
List<ILogger> loggersForBuild = [
MakeTerminalLogger(verbosity)
];

@KalleOlaviNiemitalo
Copy link

The forced TerminalLogger came from #42240. I think test/Microsoft.NET.Build.Tests/GivenThatWeWantToControlGeneratedAssemblyInfo.cs would have detected the bug if the pull request hadn't also made it ignore the progress indicators.

@martinstenhoff
Copy link
Author

@KalleOlaviNiemitalo thanks for the investigation :)

Seems like this has been raised before and we'll have to live with this for some time after GA :(
dotnet/msbuild#10841
dotnet/msbuild#10579

@KalleOlaviNiemitalo
Copy link

dotnet/msbuild#10841

That is for older versions of Windows that don't recognise the control sequences. I assume the fix would be to check the version number. That won't help with redirection.

dotnet/msbuild#10579

The fix dotnet/msbuild#10678 makes MSBuild configure the Windows console to process control sequences if TerminalLogger is used directly, and restore the original modes later. This also doesn't help with redirected output, where MSBuild should not write the control sequences at all. Although the code checks whether output is redirected, and does not configure the console in that case, it writes the control sequences anyway.

@KalleOlaviNiemitalo
Copy link

A low-risk fix would be to make dotnet-run check whether output has been redirected, and not add the TerminalLogger in that case; instead add a console logger that is configured to output only errors and warnings, and those to stderr rather than stdout.

In the longer term, I hope dotnet-run can let MSBuild create the logger objects (based on command-line options, environment variables, and redirection), and then use the same objects across restore/build/run.

@marcpopMSFT
Copy link
Member

@baronfel is MSBuild planning on some updates here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

4 participants