Question: I wrote a function that is supposed to surround some arguments with quotation marks, but it seems the program is never called.

What gets me is that when I copy/paste the console output, the program is called just fine.

Also, if all I do in the for loop is past the arguments, then it works great.

Any idea where my mistake is ?

```
public static bool callMacroProcess(String directory, String[] args, String process)
{
    String realArgs = "";
    String nextArg = "";

    foreach (String arg in args)
    {
        if (arg.StartsWith("-p="))
        {
            String tmp = arg.Substring(3);
            String argType = arg.Substring(0, 3);

            if (!String.IsNullOrWhiteSpace(tmp))
            {
                realArgs += argType + "\"" + tmp + "\" ";
            }
            else
            {
                nextArg = argType + " ";
            }
        }
        else if (!String.IsNullOrWhiteSpace(nextArg))
        {
            realArgs += nextArg + "\"" + arg + "\" ";
            nextArg = "";
        }
        else
        {
            realArgs += arg + " ";
        }
    }

    if (verbose)
    {
        Console.WriteLine("\"" + directory + process + "\" " + realArgs);
    }

    var proc = new System.Diagnostics.Process
    {
        StartInfo = new System.Diagnostics.ProcessStartInfo
        {
            FileName = "cmd.exe",
            Arguments = "/C \"" + directory + process + "\" " + realArgs,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        }
    };

    proc.Start();

    return true;
}

```

Answer: 
The way you are riding your ProcessStartInfo is incorrect. Try one of the options below. The only thing that changes between the options is the / c or / k, with a try, if not try to work with the other format.

Examples:

Run a program and pass a Filename parameter:
CMD /c write.exe c:\docs\sample.txt

Run a program and pass a Long Filename:
CMD /c write.exe "c:\sample documents\sample.txt"

Spaces in Program Path:
CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""

Spaces in Program Path + parameters:
CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2

Spaces in Program Path + parameters with spaces:
CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""

Launch Demo1 and then Launch Demo2:
CMD /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""

```
Process proc = new Process();

proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;

proc.StartInfo = new ProcessStartInfo("cmd", "/c " + directory + process + "\" "  + realArgs);

proc.Start();

```

OR

```
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;

proc.StartInfo = new ProcessStartInfo("cmd", "/k " + directory + process + "\" "  + realArgs);

proc.Start();

```
I added the process folder to my PATH. And successfully tried to call the program with the following solution : 

```
public static bool callMacroProcess(String directory, String[] args, String process)
{
    String realArgs = "";
    String nextArg = "";
    foreach (String arg in args)
    {
        if (arg.StartsWith("-p="))
        {
            String tmp = arg.Substring(3);
            String argType = arg.Substring(0, 3);
            if (!String.IsNullOrWhiteSpace(tmp))
            {
                realArgs += argType + "\"" + tmp + "\" ";
            }
            else
            {
                nextArg = argType + " ";
            }
        }
        else if (!String.IsNullOrWhiteSpace(nextArg)) //si l'argument précédent était seul
        {
            realArgs += nextArg + "\"" + arg + "\" ";
            nextArg = "";
        }
        else
        {
            realArgs += arg + " ";
        }
    }

    if (verbose)
    {
        Console.WriteLine("Arguments en parametres : " + realArgs);
    }

    System.Diagnostics.Process proc = new System.Diagnostics.Process();

    proc.StartInfo.CreateNoWindow = false;
    proc.StartInfo.UseShellExecute = false;

    proc.StartInfo = new System.Diagnostics.ProcessStartInfo(process, realArgs);

    proc.Start();

    return true;
}

```

I still can't understand why trying to call the program with CMD didn't work when I surrounded some arguments with quotation marks. At least now I can call the .exe with good arguments.