-
Notifications
You must be signed in to change notification settings - Fork 387
Added the option of not having an interactive console output. #2398
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
Conversation
…ak the collect process when no console is available.
|
Thanks @guerrerotook! |
|
Thanks @noahfalk, there is a property in the Environment class, UserInteractive, that may help us, but the Unix implementation always used true. My other approach is looking at the Console.IsInputRedirected property and if this is true do not try to move the cursor to make the update of the status. |
Thanks! Did you mean IsOutputRedirected or is it really is the input stream that matters on this one? Naively I would have guessed that moving the cursor still worked if only the input stream was redirected. |
|
The dotnet-dump analyze console uses both to detect input and output redirection: https://github.com/dotnet/diagnostics/blob/8e7cb4c8393b9b2e25d3ba7c8817c4b8b761770d/src/Microsoft.Diagnostics.Repl/Console/ConsoleProvider.cs#L77
|
josalem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution and welcome to the dotnet repos! I was a little confused when I saw this change since I recalled that dotnet-trace handled this case already. Looks like this is a regression introduced with #1968. We used to check Console.IsOutputRedirected, but #1968 switched to only checking Console.IsInputRedirected. I think we should be able to add this functionality back in by using both of those APIs without adding a new commandline flag. Would that work for the scenario you're addressing with this PR?
|
Thanks @josalem in our internal code if we only redirect the Output but not the Input its fails. Now we are testing redirecting Input and Output and we have the expect behavior. Given said that, should I close my PR or investigate why by only redirecting the Output doesn't work? |
Only redirecting output breaks because
This results in
diagnostics/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs Lines 275 to 276 in 1704288
@guerrerotook, I think changing the patch to make status printing only happen when output isn't redirected, e.g., should solve the issue. Here:
@davidwrighton please correct me if I'm wrong, but this seems like it may have been the original intent in #1968. Ideally, the result would be that the tool transparently handles redirection of input or output or both. |
|
Ah, I don't think I meant to break this. I think that change would be OK. |
|
This was fixed in #2448 |
Added the modifier --non-interactive-console that will disable the update process while collecting diagnostic information. This flag will prevent the tool to stop collecting traces when the process is being launched in a process that doesn't have a console attached to it.
That may happen when we're redirecting the standard output or when running the process inside a side car container.
[ERROR] System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top') Actual value was -1. at System.Console.SetCursorPosition(Int32 left, Int32 top) at Microsoft.Internal.Common.Utils.LineRewriter.SystemConsoleLineRewriter() in /_/src/Tools/Common/Commands/Utils.cs:line 162 at Microsoft.Internal.Common.Utils.LineRewriter.RewriteConsoleLine() in /_/src/Tools/Common/Commands/Utils.cs:line 158 at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.<>c__DisplayClass1_2.<Collect>b__4() in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 264 at Microsoft.Diagnostics.Tools.Trace.CollectCommandHandler.Collect(CancellationToken ct, IConsole console, Int32 processId, FileInfo output, UInt32 buffersize, String providers, String profile, TraceFileFormat format, TimeSpan duration, String clrevents, String clreventlevel, String name, String diagnosticPort, Boolean showchildio) in /_/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs:line 275