-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New ArgumentList constructors for Process classes #371
Comments
New APIs should go through an API review process before it is approved to start implementing.
Personally I'm not a big fan of providing new APIs just to help people writing "one-liner" codes, because often they look better written out with newlines and spaces. It also could be done already like: folded away because they're wrong 😅new ProcessStartInfo("dotnet.exe") { ArgumentList = new Collection<string> { "build", "-c Release", "-f netcoreapp5.0" }}
// Just for comparison, using the existing (string, string) ctor:
new ProcessStartInfo("dotnet.exe", "build -c Release -f netcoreapp5.0") Compared to the constructor version, I see little difference: new ProcessStartInfo("dotnet.exe", new Collection<string> { "build", "-c Release", "-f netcoreapp5.0" }) With that said though, perhaps passing in multiple arguments when launching a process is a common enough scenario (e.g. Maybe |
Wait, the initializer list works? I thought it only worked on properties with a My request for this stemmed from PowerShell/PowerShell#1995, so it mainly is intended for these less sugary languages. Since |
They work for any type that implements But yes, it only works on construction. |
Actually, My bad. |
@Gnbrkm41 You don't need to assign new ProcessStartInfo
{
ArgumentList = {
"arg1",
"arg2",
}
} |
This would be nice because it would handle some escaping issues. For example, passing a path containing a space to a command-line tool. This is a common source of bugs and I think writing a correct escaping algorithm is not entirely trivial. |
I like this proposal and I think it's worth discussing it during API Review. Since public class Process
{
public static System.Diagnostics.Process Start(string fileName, Collection<string> arguments);
}
public class ProcessStartInfo
{
public ProcessStartInfo(string fileName, Collection<string> arguments)
} |
namespace System.Diagnostics
{
public partial class Process
{
// Existing overloads:
// public static Process Start(string fileName);
// public static Process Start(string fileName, string arguments);
// public static Process Start(string fileName, string userName, SecureString password, string domain);
// public static Process Start(string fileName, string arguments, string userName, SecureString password, string domain);
// public static Process Start(ProcessStartInfo startInfo);
public static Process Start(string fileName, IEnumerable<string> arguments);
}
} |
Although the ArgumentList property has been added to System.Diagnostics.ProcessStartInfo as a way to relatively safely pass command line arguments, there is no simple, one-liner way to use this interface. This proposal seeks to add such an interface wherever a constructor or static function accepts the older
string arguments
initializer.Applies to:
Changes requested:
S.D.P::Start(string fileName, IReadOnlyCollection<string> argumentList);
S.D.PSI::new(string fileName, IReadOnlyCollection<string> argumentList);
The
fileName
parameter retains the same semantics as in the other constructors. In line with howarguments
is handled, the newargumentList
parameter shall be copied to the internalArgumentList
property.Non-goals:
Arguments
.(How does the contribution thing works anyway? I guess I will open an issue first since I am on my phone.)
The text was updated successfully, but these errors were encountered: