Reputation: 21280
I have following list of arguments that I want to run some application with.
"C:\Release one" "My Manager" 321
I see that I should put them to ProcessStartInfo
Arguments
property.
But how do I write them correctly because they have spaces in the strings, "My Manager"
?
Upvotes: 2
Views: 517
Reputation: 1164
I'm using this methot to get CorrectaArgumentvalue
public static string GetArgumentValue(string arg)
{
if (arg.Contains(" "))
return string.Format("\"{0}\"", arg);
return arg;
}
Example:
process.StartInfo.Arguments = string.Format("{0} {1} {2}", GetArgumentValue(@"C:\Release one"), GetArgumentValue("My Manager"), 321);
Upvotes: 0
Reputation: 443
Use this:
System.Diagnostics.Process.Start("something.exe","arg_1"+" "+"arg_2"+" "+"arg_3"+" ");
Upvotes: 1
Reputation: 1532
Escape the " and the \
Example:
Process p = new Process();
p.StartInfo.FileName = "C:\\Release one";
p.StartInfo.Arguments = "\"My Manager\" 321";
p.Start();
Upvotes: 0
Reputation: 704
Try...
"\"C:\\Release one\""
"\"My Manager\""
321
I've not tried this in your particular situation, but it is the standard way to include double quote as a part of the string.
Upvotes: 0
Reputation: 17868
You need to place them as you show there, in quotes.
So the code might look like
Process.Start("myexe.exe","\"My stuff\" "+myarg);
Upvotes: 0