Arguments are received as string[] in a fresh program. They are already parsed correctly, so quotes will keep a parameter together, even though it may be a path that contains spaces. Nice.
I now want to forward them to a new Process, but ProcessStartInfo only supports string to define arguments.
So, just concatenating them with spaces is wrong, as paths may then be split into multiple arguments. I'm also unsure if wrapping them in quotes and then concatening them with spaces works in every instance - I don't think so, as the target program may not see -u and "-u" as equivalent. Is there a clean way to do this in .NET Framework?
ProcessStartInfo also has an ArgumentList property which allows for passing multiple arguments.
ArgumentListand theArgumentsproperty are independent of one another and only one of them can be used at the same time. The main difference between both APIs is thatArgumentListtakes care of escaping the provided arguments and internally builds a single string that is passed to operating system when callingProcess.Start(info). So if you are not sure how to properly escape your arguments, you should chooseArgumentListoverArguments.
Reference
Applies to
| Product | Versions |
|---|---|
| .NET | .NET 5, .NET 6, .NET Core 2.1, .NET Core 2.2, .NET Core 3.0, .NET Core 3.1 |
| .NET Standard | 2.1 |
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With