Add Process constructor accepting SafeProcessHandle and optional stream handles#128491
Draft
Copilot wants to merge 4 commits into
Draft
Add Process constructor accepting SafeProcessHandle and optional stream handles#128491Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
…ream handles Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3a2f55b9-2cc6-46ba-87af-1dc53029c488 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…unused usings Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/3a2f55b9-2cc6-46ba-87af-1dc53029c488 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
adamsitnik
May 22, 2026 15:49
View session
adamsitnik
reviewed
May 22, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
…ANDLE_VALUE, extract CreateProcessWithHandles helper Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/12cdb475-8f8c-4309-b5d7-d0b02c675048 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
Done in a53a1fc. All three items addressed:
|
adamsitnik
reviewed
May 22, 2026
… Windows Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/b6feaf9e-a3a5-4056-a01a-9aa9761be8be Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new public
Processconstructor that creates instances from user-provided safe handles, enabling advanced interop scenarios where users callCreateProcess(or equivalent) directly but still wantProcessclass features like async stream reading andWaitForExit.API Addition
On Windows,
standardOutputandstandardErrorhandles must be opened for asynchronous I/O (IsAsync == true); anArgumentExceptionis thrown otherwise.Changes
ref/System.Diagnostics.Process.cs): New constructor signatureProcess.cs): Constructor wires up handle, process ID, and wraps optional file handles intoStreamWriter/StreamReaderusing existingOpenStream+ encoding logic. Validates thatstandardOutput/standardErrorhandles are async on Windows.ProcessHandlesTests.Windows.cs):RunWithInvalidHandles→RunWithHandlesparameterized by handle values andbInheritHandlesCreateProcessWithHandlesstatic helper that encapsulates theCreateProcessP/Invoke logic, reused by bothRunWithHandlesand the new testINVALID_HANDLE_VALUEconstant to replace magic numbersProcessStartedWithAnonymousPipeHandles_CanCaptureOutputtest: creates async anonymous pipes viaSafeFileHandle.CreateAnonymousPipe(asyncRead: true), enables inheritance viaSetHandleInformation, spawns child process using the shared helper, wraps read handles in newProcessctor, usesReadAllText()to assert captured stdout/stderr.csproj): AddedInterop.HandleInformation.cscommon sourceStrings.resx): AddedArgument_HandleNotAsyncerror messageUsage Example