Add StandardInputHandle/OutputHandle/ErrorHandle SafeFileHandle properties 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>
|
@tmds @jkotas @stephentoub the PR is ready for review |
Co-authored-by: Jan Kotas <jkotas@microsoft.com> Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
🤖 Copilot Code Review — PR #125848Note This review was generated by GitHub Copilot using automated code analysis. Holistic AssessmentMotivation: The PR adds Approach: The approach is clean — new nullable Summary: Detailed Findings
|
|
/ba-g the failure are unrelated |
Description
Adds three new
SafeFileHandle?properties toProcessStartInfothat allow passing file handles directly to child processes, bypassing theRedirectStandard*pipe-based mechanism.The caller is responsible for disposing the handles after starting the child process.
Changes
ProcessStartInfo.cs: NewStandardInputHandle,StandardOutputHandle,StandardErrorHandleauto-properties (SafeFileHandle?) with XML docs. Remarks document that handles do not need to be inheritable (the runtime will duplicate them as inheritable if needed), list typical APIs (SafeFileHandle.CreateAnonymousPipe,System.IO.File.OpenHandle,System.IO.File.OpenNullHandle,System.Console.OpenStandardInputHandle/OpenStandardOutputHandle/OpenStandardErrorHandle), and document constraints withRedirectStandard*/UseShellExecute. XML doc cref references use fully qualified names.ref/System.Diagnostics.Process.cs: Public API surface additions forStandardInputHandle,StandardOutputHandle,StandardErrorHandle.Process.csvalidation: When anyStandard*Handleis set,UseShellExecutemust befalseand the correspondingRedirectStandard*must also befalse. Reuses existingSR.CantRedirectStreamserror message for theUseShellExecutecheck. AValidateHandlehelper method checks each provided handle forIsInvalidfirst (throwsArgumentException) thenIsClosed(throwsObjectDisposedException), following the same pattern asFileStream.ValidateHandle.Process.cspipe creation: New handles take priority over default stdin/stdout/stderr inheritance. Handles provided by the caller are never disposed byProcess.Start; only internally-created handles (pipes, inherited console handles) are disposed.Process.Windows.cs:DuplicateAsInheritableIfNeededhelper that checksGetHandleInformationbefore duplicating — avoids unnecessary duplication when the handle is already inheritable.Interop.ForkAndExecProcess.cs: Uses per-handleDangerousAddReftracking booleans (stdinRefAdded,stdoutRefAdded,stderrRefAdded) to ensureDangerousReleaseis only called on handles that were successfully addref'd.Strings.resx: New error stringsCantSetHandleAndRedirectandArg_InvalidHandle.ProcessHandlesTests.cs: Tests for pipe redirection (single/dual/shared pipes), inherited handles, piping between processes withFile.OpenHandle, and validation error cases (handle+redirect, handle+shell-execute, default null, set-and-get).💬 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.