Skip to content

Handle redirected input/output in collect-linux#5745

Open
zachcmadsen wants to merge 2 commits intodotnet:mainfrom
zachcmadsen:collect-linux-redirected-io
Open

Handle redirected input/output in collect-linux#5745
zachcmadsen wants to merge 2 commits intodotnet:mainfrom
zachcmadsen:collect-linux-redirected-io

Conversation

@zachcmadsen
Copy link
Contributor

Console.KeyAvailable and LineRewriter.RewriteConsoleLine throw exceptions when input and output are redirected.

dotnet-trace collect works with both redirected and has similar code to what's proposed here.

@zachcmadsen zachcmadsen requested a review from a team as a code owner March 4, 2026 01:58
Copilot AI review requested due to automatic review settings March 4, 2026 01:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates dotnet-trace collect-linux to avoid console APIs that throw when stdin/stdout are redirected, aligning behavior with dotnet-trace collect.

Changes:

  • Add internal flags to disable “stop on Enter” when input is redirected.
  • Disable status/progress line rewriting when output is redirected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 503 to 504
if (printStatusUpdate && ot == OutputType.Progress)
{
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

When input is redirected, stopOnEnter is false, but the progress output printed in this block still says "Press ...". Please adjust the message (or conditionally print it) so it doesn't instruct the user to press Enter when Enter won't be observed.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Is IsInputRedirected=true + IsOutputRedirected=false useful? I'm guessing we haven't had users hitting that scenario given CollectCommand.cs doesn't condition its "Press ..." message either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdh1418 I opted to leave it as is given that collect doesn't do that. Up to you though

mdh1418
mdh1418 previously approved these changes Mar 4, 2026
Copy link
Member

@mdh1418 mdh1418 left a comment

Choose a reason for hiding this comment

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

Thanks, we should add some unit tests to CollectLinuxCommandFunctionalTests for these scenarios if we can.

private long statusUpdateTimestamp;
private Version minRuntimeSupportingUserEventsIPCCommand = new(10, 0, 0);
private readonly bool cancelOnEnter = true;
private readonly bool printStatusOverTime = true;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't think there is any reason to init these if the constructor will re-init them.

Copy link
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

Thanks Zach, this looks nice to me. I'm happy to take this whenever you and Mitchell are satisfied with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants