I want to run simple CMD
command and my argument
contains spaces (" ").
In this case this is not working since its recognized as command with several arguments
...
This is what I have tried (same results):
string arg = "c:\my path\ this is test\file.doc";
string.Format("\"{0}\"", arg)
Edit:
public void Invoke(string fileName, string arg)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.FileName = fileName;
if (arg != "")
processStartInfo.Arguments = arg;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = processStartInfo;
process.Exited += Process_Exited;
process.EnableRaisingEvents = true;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
Usage:
string arg = "c:\my path\this is my string.ps1";
Invoke(@"C:\windows\system32\windowspowershell\v1.0\powershell.exe", string.Format("\"{0}\"", arg));