2

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"?

1
  • I assume that you tried placing double-quotes around the elements, right? Commented Aug 23, 2012 at 12:09

6 Answers 6

5

Try:

process.StartInfo.Arguments = "\"My Manager\" 321";
Sign up to request clarification or add additional context in comments.

Comments

1

Use this:

 System.Diagnostics.Process.Start("something.exe","arg_1"+"  "+"arg_2"+"  "+"arg_3"+"  ");

1 Comment

No, you need to properly build the string as though you were writing arguments in the command line.
0

You need to place them as you show there, in quotes.

So the code might look like

Process.Start("myexe.exe","\"My stuff\" "+myarg);

Comments

0

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.

Comments

0

Escape the " and the \

Example:

Process p = new Process();
p.StartInfo.FileName = "C:\\Release one";
p.StartInfo.Arguments = "\"My Manager\" 321";
p.Start();

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.