title: C# run batch file with argument with spaces
body: <p>I need to run batch file, which has path (can contains spaces) as argument.</p>
  
  <p>Batch file is really simple:</p>
  
  <blockquote>
    <p>echo off</p>
    
    <p>echo %1 > echotest.txt</p>
  </blockquote>
  
  <p>Csharp code I am using to run this batch file:</p>
  
  <pre><code>   ProcessStartInfo info = new ProcessStartInfo();
                          info.UserName = KIM_USER;
                          info.Password = ConvertToSecureString(KIM_USER_PASSWORD);
                          info.FileName = theTask.Path;
                          info.Arguments = "\"" + TranslateParameter(theTask.Parameter) + "\"";
                          info.Domain = Environment.MachineName;
                          info.WorkingDirectory = Path.GetDirectoryName(theTask.Path);
                          info.UseShellExecute = false;
                          info.CreateNoWindow = true;
                          Process batProcess = Process.Start(info);
                          batProcess.WaitForExit();
  </code></pre>
  
  <p>Basically in parameter comes e.g {Test_Path} and this is in TranslateParameter converted to real path, e.g: D:\Test Path\ (contains spaces)</p>
  
  <p>This does not work for me, it returns me exit code 1 everytime.</p>
  
  <p>If i remove \" from info.Arguments, it works, but in output file is just D:\Test</p>
  
  <p>Any suggestions?</p>
  
  <p>Regards</p>