Add StandardInputHandle/OutputHandle/ErrorHandle SafeFileHandle properties and LeaveHandlesOpen to ProcessStartInfo#125848
Add StandardInputHandle/OutputHandle/ErrorHandle SafeFileHandle properties and LeaveHandlesOpen to ProcessStartInfo#125848
Conversation
…ation and stream setup to Process.cs Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…nterop.Pipe.cs to csproj Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…eAnonymousPipe directly, simplify Windows StartWithCreateProcess Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
- STARTF_USESTDHANDLES is always provided now - we may use more flags in the future - so ProcessWindowStyle tests should check only if STARTF_USESHOWWINDOW (1) was applied
…n Android (it's not supported)
… 0/1/2; remove Android checks from Process.cs Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…rning fd 0/1/2; remove Android checks from Process.cs" This reverts commit bba0144.
…artInfo Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
…ndle nullable handles Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/264e5c0b-daf2-4f32-80ec-10fdf888c120
…eam (possibly a terminal) Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/264e5c0b-daf2-4f32-80ec-10fdf888c120
…ot/add-standard-input-output-properties
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please apply my suggestions and add one more test that uses File.OpenHandle to open a file handle for writing, set it via StandardOutput property and set LeaveHandlesOpen to true and verify that after starting the process the handle is still opened. Please choose command line utility that is available on every OS (hostname? whoami? pwd?)
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/tests/ProcessHandlesTests.cs
Outdated
Show resolved
Hide resolved
…() calls, add LeaveHandlesOpen test Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/6c515d2e-34b7-483e-a1e5-2b0fae3caad8
Applied both suggestions and added the |
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// The handle does not need to be inheritable; the runtime will make it inheritable as needed. |
There was a problem hiding this comment.
Is "as needed" correct? The implementation in the other PR is duplicating it as inheritable unconditionally.
There was a problem hiding this comment.
Not yet, that is why I want to introduce SafeFileHandle.IsInheritable in #125838.
There was a problem hiding this comment.
Updated wording to "the runtime will duplicate it as inheritable" in 7920b52.
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
- add more tests - fix bugs - handle edge cases
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
Show resolved
Hide resolved
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// The handle does not need to be inheritable; the runtime will make it inheritable as needed. |
There was a problem hiding this comment.
Not yet, that is why I want to introduce SafeFileHandle.IsInheritable in #125838.
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs
Outdated
Show resolved
Hide resolved
…/ErrorHandle, fix docs, add handle validation Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/7c3e65ca-2e62-4821-b8d2-0bc9bde12049
All feedback addressed in 7920b52: renamed properties to |
Description
Adds three new
SafeFileHandle?properties and aLeaveHandlesOpenproperty toProcessStartInfothat allow passing file handles directly to child processes, bypassing theRedirectStandard*pipe-based mechanism.By default,
Process.Startdisposes the standard handles after starting the child process. SetLeaveHandlesOpentotrueto keep them open for the caller to manage.Changes
ProcessStartInfo.cs: NewStandardInputHandle,StandardOutputHandle,StandardErrorHandleauto-properties (SafeFileHandle?) with XML docs. Remarks document that handles do not need to be inheritable (the runtime duplicates them as inheritable), and list typical APIs (SafeFileHandle.CreateAnonymousPipe,File.OpenHandle,File.OpenNullHandle,Console.OpenStandardInputHandle/OpenStandardOutputHandle/OpenStandardErrorHandle), interaction withLeaveHandlesOpen, and constraints. NewLeaveHandlesOpenproperty (bool, defaultfalse) controlling whether handles are disposed after process start.ref/System.Diagnostics.Process.cs: Public API surface additions forStandardInputHandle,StandardOutputHandle,StandardErrorHandle, andLeaveHandlesOpenProcess.csvalidation: When anyStandard*Handleis set,UseShellExecutemust befalseand the correspondingRedirectStandard*must also befalse. Reuses existingSR.CantRedirectStreamserror message for theUseShellExecutecheck. AValidateHandlehelper method checks each provided handle forIsClosed(throwsObjectDisposedException) andIsInvalid(throwsArgumentException), following the same pattern asFileStream.ValidateHandle.Process.cspipe creation: New handles take priority over default stdin/stdout/stderr inheritance. Handles are always disposed after starting the child process unlessLeaveHandlesOpenistrue.Strings.resx: New error stringsCantSetHandleAndRedirectandArg_InvalidHandleProcessHandlesTests.cs: Tests for pipe redirection, inherited handles, piping,LeaveHandlesOpenbehavior withFile.OpenHandle, and validation error cases. Includes aLeaveHandlesOpen_KeepsHandleOpentest that verifies handles remain open afterProcess.StartwhenLeaveHandlesOpenistrue, usinghostnameas a cross-platform command andFile.OpenHandlefor the output file.💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.