Reputation: 131
i'm trying to parse a command to the CMD and to process the return value. Although the escaping of my command is just fine the CMD throws an error 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
Console.WriteLine("Starting file compare...");
string strCmdText = "/K \"" + ocrPath + "\\" + comparetool + "\" -compare \"" + ocrPath + "\" Nuance";
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
The escaping of the string strCmdText deliefers the following output/command:
/K "C:\Program Files (x86)\Common Files\Alpha\OCR\Alpha.Tools.ToolkitDistribution.exe" -compare "C:\Program Files (x86)\Common Files\Alpha\OCR" Nuance
which is exactly what i need. If i type this command into the command prompt the .exe will execute and deliver a %errorlevel%. But it doesn't like it wrote in the beginning. What do i miss here?
Upvotes: 1
Views: 66
Reputation: 3037
Since everything after the /K is transferred to a second command shell, that whole thing needs to be packed in an extra pair of "
//string strCmdText = "/K \"" + ocrPath + "\\" + comparetool + "\" -compare \"" + ocrPath + "\" Nuance";
string strCmdText = "/K \"\"" + ocrPath + "\\" + comparetool + "\" -compare \"" + ocrPath + "\" Nuance\"";
Upvotes: 2