Repository navigation
Closed
Labels
Milestone
Description
Background and motivation
The new Process.Run() and related methods take an IList<string> for command arguments.
It should use IEnumerable<string> instead for correctness, and to be in line with the Process.Start() counterpart.
API Proposal
namespace System.Diagnostics
{
public partial class Process
{
public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeout = default);
- public static ProcessExitStatus Run(string fileName, IList<string>? arguments = null, bool silent = false, TimeSpan? timeout = default);
+ public static ProcessExitStatus Run(string fileName, IEnumerable<string>? arguments = null, bool silent = false, TimeSpan? timeout = default);
public static ProcessTextOutput RunAndCaptureText(ProcessStartInfo startInfo, TimeSpan? timeout = default);
- public static ProcessTextOutput RunAndCaptureText(string fileName, IList<string>? arguments = null, TimeSpan? timeout = default);
+ public static ProcessTextOutput RunAndCaptureText(string fileName, IEnumerable<string>? arguments = null, TimeSpan? timeout = default);
public static Task<ProcessTextOutput> RunAndCaptureTextAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default);
- public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IList<string>? arguments = null, CancellationToken cancellationToken = default);
+ public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IEnumerable<string>? arguments = null, CancellationToken cancellationToken = default);
public static Task<ProcessExitStatus> RunAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default);
- public static Task<ProcessExitStatus> RunAsync(string fileName, IList<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default);
+ public static Task<ProcessExitStatus> RunAsync(string fileName, IEnumerable<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default);
public bool Start();
public static Process? Start(ProcessStartInfo startInfo);
public static Process Start(string fileName);
public static Process Start(string fileName, string? arguments);
public static Process Start(string fileName, IEnumerable<string> arguments);
public static int StartAndForget(ProcessStartInfo startInfo);
- public static int StartAndForget(string fileName, IList<string>? arguments = null);
+ public static int StartAndForget(string fileName, IEnumerable<string>? arguments = null);
}
}API Usage
No change for existing callers.
Alternative Designs
IReadOnlyList<string> is also a valid option.
But IEnumerable<string> will allow it to be dropped in as a replacement for more existing code, and I can see neither Count nor the indexer are used in the current implementation.
Risks
This is a breaking change. But I don't think it's beyond what's expected in Preview/RC.
Reacted by strangeman375, TheTomatoKing, campersau and Ilja Nosik
Reacted by Theodore Tsirpanis and OmariO
Activity
dotnet-policy-service commentedon Jul 8, 2026
Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.
teo-tsirpanis commentedon Jul 8, 2026
Accepting
IEnumerable<string>would be quite restrictive and preclude the implementation code from enumerating it multiple times, or getting its length.IReadOnlyList<string>would be better, but not much better than the status quo.dotnet-policy-service commentedon Jul 8, 2026
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.
TheTomatoKing commentedon Jul 8, 2026
@teo-tsirpanis
I think it's worth encouraging refactors from older
Process.Start()patterns to the newProcess.Run()methods where possible.Especially when reading output of a process. Since that can cause deadlocks if not careful, and probably does in a lot of existing code.
This is why I suggested making
Process.Run()take anIEnumerable<string>, since that would be a very easy change and make it a drop-in replacement in even more cases.I do see the point that future implementation could take advantage of
IReadOnlyList<string>'s interface. So that may be the better choice in the long run.But to me the use of
IList<string>indicates an intent for the method to possibly modify the collection. Which in this case it should never do.So either of
IReadOnlyList<string>orIEnumerable<string>would be more correct. And IMO any public library should try to promote such "correctness" where possible, especially core libraries.With the way it currently works, if I write a method that wraps
Process.Run(), I have the following options:IList<string>parameter instead ofIReadOnlyList<string>. Potentially making it ambiguous whether the collection will be modified.IReadOnlyList<string>and copy it to an intermediary list, whichProcess.Run()will then create its own copy of.Process.Run()was designed to simplify.Considering how common that is, isn't it worth getting it right, so people can write simpler and more correct code?
Wasn't that the point of these methods in the first place? And isn't the point of Preview versions to get it right before GA?
huoyaoyuan commentedon Jul 9, 2026
The pre-existing
ProcessStartInfoconstructor andProcess.Startoverload are both usingIEnumerable<string>.JakeYallop commentedon Jul 9, 2026
Is it critical that the list isn't modified after being passed in? If that is the case, then
IEnumerable+ taking a defensive copy feels better to me as well (or using some other read only interface).TheTomatoKing commentedon Jul 9, 2026
@JakeYallop The current implementation creates a defensive copy using a
forecahloop. Besides that, it doesn't touch the original collection.JakeYallop commentedon Jul 9, 2026
Thanks.
That makes the choice of
IList<string>feel even weirder to me then.TheTomatoKing commentedon Jul 9, 2026
@JakeYallop It gets even stranger.
Similar to it's
Process.Start()equivalent, it usesProcessStartInfounder the hood.But unlike
Process.Start(), it neglects to use theProcessStartInfo(string fileName, IEnumerable<string> arguments)ctor which uses.ToList()to create the defensive copy and populateProcessStartInfo.ArgumentListin one go.Instead,
Process.Run()forecahes over the collection, populatingProcessStartInfo.ArgumentListone item at a time.That isn't a huge deal. But the whole thing put together smells of AI code with lack of proper review to me.
adamsitnik commentedon Jul 13, 2026
Hi @TheTomatoKing
Thank you for your feedback. The new APIs are correct (arguments provided by the users are not modified), but as you have pointed out, not consistent with the older APIs (that accept
IEnumerable<string>). The reasons for that is not "AI code with lack of proper review" (LOL). I just wanted them to avoid hidden allocations like this:runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessStartInfo.cs
Line 71 in 45286f4
Having said that, I am going to present this API update to the API Review Board. We don't have much time (code complete for the last preview is 16th of July) so I am going to mark this proposal as blocking.
Thanks
9 remaining items
ladeak commentedon Jul 14, 2026
Could this have
params, so that the parameter would be:params IEnumerable<string>? arguments = null? It would cause an issue with the order or parameters, but when I tried to use the API in the current preview it would have felt natural to pass string arguments as params as opposed to a collection expression.adamsitnik commentedon Jul 21, 2026
We provide sync and async overloads, IIRC the
CancellationTokenneeds to be the last argument for async methods, so we could not useparams IEnumerable<string>for the async overloads.We could do it for
StartAndForget(no other arguments or async overload), but I am not sure whether it's worth it. And also what is the story forparam IEnumerablein F#bartonjs commentedon Jul 21, 2026
This increases consistency of the Process class, looks good as proposed.
namespace System.Diagnostics { public partial class Process { public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeout = default); - public static ProcessExitStatus Run(string fileName, IList<string>? arguments = null, bool silent = false, TimeSpan? timeout = default); + public static ProcessExitStatus Run(string fileName, IEnumerable<string>? arguments = null, bool silent = false, TimeSpan? timeout = default); public static ProcessTextOutput RunAndCaptureText(ProcessStartInfo startInfo, TimeSpan? timeout = default); - public static ProcessTextOutput RunAndCaptureText(string fileName, IList<string>? arguments = null, TimeSpan? timeout = default); + public static ProcessTextOutput RunAndCaptureText(string fileName, IEnumerable<string>? arguments = null, TimeSpan? timeout = default); public static Task<ProcessTextOutput> RunAndCaptureTextAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default); - public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IList<string>? arguments = null, CancellationToken cancellationToken = default); + public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IEnumerable<string>? arguments = null, CancellationToken cancellationToken = default); public static Task<ProcessExitStatus> RunAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default); - public static Task<ProcessExitStatus> RunAsync(string fileName, IList<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default); + public static Task<ProcessExitStatus> RunAsync(string fileName, IEnumerable<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default); public static int StartAndForget(ProcessStartInfo startInfo); - public static int StartAndForget(string fileName, IList<string>? arguments = null); + public static int StartAndForget(string fileName, IEnumerable<string>? arguments = null); } }Change IList<string> to IEnumerable<string> in Process Run/StartAndFo…
adamsitnik commentedon Jul 22, 2026
The change will be included in .NET 11 Preview 7.
omariom commentedon Jul 22, 2026
IReadOnlyList materializes before the API call, while IEnumerable materializes inside it.
With a failing LINQ query, this can make the API appear in the call stack even when it isn't the cause.
huoyaoyuan commentedon Jul 22, 2026
This is applicable to any API accepting
IEnumerable.