You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
File: low-level APIs for opening null device #122803
As of today, BCL does not provie any API for discarding standard input, output, or error of the started process in optimal way. Because of that, users often read the STD OUT/ERR just to ignore it, which is very inefficient. Sample from our code base:
process.StartInfo.RedirectStandardOutput=true;process.StartInfo.RedirectStandardError=true;// Send the output and error streams to empty handlers because the text is also written to the log filesprocess.OutputDataReceived+=(sender,e)=>{};process.ErrorDataReceived+=(sender,e)=>{};process.Start();process.BeginOutputReadLine();process.BeginErrorReadLine();
This could be avoided if we give the users the ability to open handles to the null device (NUL on Windows, /dev/null on Unix). Those handles can then be passed to the process creation APIs to discard unwanted output or provide empty input.
API Proposal
namespace System.IO;
public static class File
{
+ public static SafeFileHandle OpenNullFileHandle();
public static SafeFileHandle OpenHandle(string path, FileMode mode = FileMode.Open, FileAccess access = FileAccess.Read,
FileShare share = FileShare.Read, FileOptions options = FileOptions.None, long preallocationSize = 0);
}
Not in the API design, but the implementations need to enforce CLOEXEC (Unix) / bInheritHandle: false (Windows) semantics on the opened handle to avoid leaking it to child processes unintentionally.
Activity
dotnet-policy-service commentedon Dec 31, 2025
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
adamsitnik commentedon Jan 20, 2026
As pointed by @stephentoub in the API review, the tests should ensure it works with
FileStream(handle, useAsync: true)bartonjs commentedon Jan 20, 2026
Video
OpenNullHandle()