Reputation: 948
I want to call a Process from C# with multiple parameters.
When i call:
ProcessStartInfo info = new ProcessStartInfo();
...
info.Arguments = "argument";
Process.Start(info);
i can only set a String
as attribute. (Same to all types of the Start method)
Is there a way to set a String[]
as arguments or how does this String
getting interpreted?
Because on the other side
static void Main(string[] args)
i am getting a String[]
.
Thanks in advance.
Upvotes: 1
Views: 2086
Reputation: 186833
Technically you can do it like that:
string[] args = new String[] {"argument1", "argument2", "argument3"};
...
info.Arguments = String.Join(" ", args);
the restriction is that args should not have arguments with spaces
Upvotes: 3
Reputation: 53958
Is there a way to set a String[] as argument?
No you can't do this, since the type of ProcessStartInfo.Arguments
is string
. Hence you can assign to it an array of strings.
You could pass to this string the parameters as follows:
info.Arguments = "argument1 argument2 argument3";
and your .exe will be executed as you were passing an array of strings with elements (argument1
,argument2
,argument3
).
Upvotes: 2