Uh oh!
There was an error while loading. Please reload this page.
Add File.OpenNullHandle() for efficient process I/O redirection - #123483
Conversation
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…ests Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Tagging subscribers to this area: @dotnet/area-system-io |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
This PR adds a new File.OpenNullHandle() API to efficiently obtain a handle to the system's null device (NUL on Windows, /dev/null on Unix). This enables efficient process I/O redirection by discarding output or providing empty input without the overhead of reading and ignoring data.
Changes:
- Added new public API
File.OpenNullHandle()to theSystem.IO.Fileclass - Implemented platform-specific core methods that open the null device with read/write access and non-inheritable handles
- Added comprehensive test coverage with 14 test cases covering sync/async read/write operations
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Runtime/ref/System.Runtime.cs | Added public API signature for OpenNullHandle() method |
| src/libraries/System.Private.CoreLib/src/System/IO/File.cs | Added public OpenNullHandle() method with comprehensive XML documentation |
| src/libraries/System.Private.CoreLib/src/System/IO/File.Windows.cs | Implemented Windows-specific core that opens "NUL" device with non-inheritable handle |
| src/libraries/System.Private.CoreLib/src/System/IO/File.Unix.cs | Implemented Unix-specific core that opens "/dev/null" device with O_CLOEXEC (non-inheritable) |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/System.IO.FileSystem.Tests.csproj | Added test file reference to project |
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/OpenNullHandle.cs | Added comprehensive tests for sync/async read/write operations and concurrent access |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
commented
Jan 30, 2026
/ba-g infrastructure timeouts |
Description
Adds
File.OpenNullHandle()API to obtain a handle to the system's null device (NULon Windows,/dev/nullon Unix). This enables efficient discarding of process output/error streams or providing empty input without the overhead of reading and ignoring data.Current inefficient pattern:
New API:
Changes
File.OpenNullHandle()toSystem.IO.FileNullDevicePathconstants inFile.Windows.cs("NUL") andFile.Unix.cs("/dev/null")File.cscallsSafeFileHandle.Open()with the platform-specific path constantFileOptions.None(enforcesO_CLOEXECon Unix for non-inheritability)O_CLOEXEC)FileStream, including:FileStream(handle, FileAccess.*)constructorsisAsyncparameter was attempted but reverted due to FileStream validation preventing use of sync handles withisAsync: true(tracked separately in issue Remove isAsync flag validation fromFileStreamctors #123760)Testing
All tests passing. Verified:
FileStream(handle, FileAccess.*)constructorsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.