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

Add API for detecting broken pipe when write to stdout(or stderr) #30540

Closed
itn3000 opened this issue Aug 9, 2019 · 1 comment
Closed

Add API for detecting broken pipe when write to stdout(or stderr) #30540

itn3000 opened this issue Aug 9, 2019 · 1 comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Console needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Milestone

Comments

@itn3000
Copy link
Contributor

itn3000 commented Aug 9, 2019

currently, corefx's System.Console.Out implementation is ignoring broken pipe, just pretend to success.(due to #15587)

This behavior is sometimes inconvenient when work together with some command like head command.
if dotnet command output is very long, there is no easy way to stop program if command which follows after pipe stop (except using native API, but it is sometimes very difficult).

So, I want the API to detect whether stdout(and maybe stderr) is broken.

@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 5.0 milestone Feb 1, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@eiriktsarpalis eiriktsarpalis self-assigned this Jun 22, 2020
@eiriktsarpalis eiriktsarpalis modified the milestones: 5.0.0, Future Jun 29, 2020
@adamsitnik adamsitnik removed the untriaged New issue has not been triaged by the area owner label Jul 6, 2020
@eiriktsarpalis eiriktsarpalis added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jan 27, 2021
@eiriktsarpalis eiriktsarpalis removed their assignment Oct 11, 2021
@adamsitnik adamsitnik removed their assignment Nov 13, 2023
@adamsitnik
Copy link
Member

Triage: I don't believe that we can provide reliable API for this feature request. To check whether pipe is broken, we would need to perform a write. Writing 0 bytes has a special meaning (#81053), so writing 0 bytes is not an option. Changing the behavior to always throw in such cases is also not an option, as it would break plenty of apps (especially those which are printing to console while the process is shutting down).

Since there was only one up-vote, the best I can do right now is to provide a workaround:

static void Workaround(string text, out bool brokenPipe)
{
    Console.Write(text);
    brokenPipe = Marshal.GetLastWin32Error() == (OperatingSystem.IsWindows() ? 0x6D : 0x10043);
}

@adamsitnik adamsitnik closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Console needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

5 participants