Process.start with multiple command line arguments..

I am trying to call an exe file with multiple command line arguments in C# and capture the output but unsuccessful. Here is what I am doing:

Process process = new Process();

process.StartInfo.UseShellExecute = false;

process.StartInfo.RedirectStandardOutput = true;

process.StartInfo.RedirectStandardError = true;

process.StartInfo.CreateNoWindow = true;

process.StartInfo.FileName = @"D:\bin\test.exe";

process.StartInfo.Arguments = "-a ipaddress -L C:\\test.txt";

process.Start();

string s = process.StandardOutput.ReadToEnd();

MessageBox.Show(s);

It works fine when run the exe on command line with those arguments. Am I doing anything wrong here

thanks a lot for help!

Sue



Answer this question

Process.start with multiple command line arguments..

  • JonCole

    ssli2005 wrote:

    process.StartInfo.FileName = @"D:\bin\test.exe";

    process.StartInfo.Arguments = "-a ipaddress -L C:\\test.txt";

    These two lines will be a problem. Use the @ so that backslash is treated literally and not as an escape.


  • Malcatrazz

    That's odd, because it should have worked that way it was. What was the problem you were having

  • ImNoScrub

    Thanks! I splited the arguments string like this and it works :

    process.StartInfo.Arguments = "-a ipaddress -L " + @"C:\test.txt;


  • FR6

    Nice post, useful very much. I was just working on this last hour.

    I believe the simplest way to get around this is

    process.StartInfo.Arguments = @"-a ipaddress -L C:\test.txt";

    Solves everything.


  • Process.start with multiple command line arguments..