I have a problem starting a process in C# when there’s a space in the path on Windows 8, even when the path is in double quotes!
The following code has been working fine for years on our XP and Windows 7 machines, but we recently switched some development boxes over to Windows 8 and we now get the following error:
'D:\Workspace\Visual' is not recognized as an internal or external command, operable program or batch file.
Code:
string command = "\"D:\\Workspace\\Visual Studio 2010\\Dev\\Tools\\Editors\\AssetManager\\bin\\Tools\\TextureAtlasBuilder.exe\"";
string arguments = "\"D:\\Local\\Temp\\xu2twc4d.cg1\" \"environment-textures\"";
ProcessStartInfo startInfo = new ProcessStartInfo
{
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardError = true,
RedirectStandardOutput = true,
FileName = string.Format(CultureInfo.InvariantCulture, @"{0}\cmd.exe", Environment.SystemDirectory),
Arguments = string.Format(CultureInfo.InvariantCulture, "/C {0} {1}", command, arguments)
};
Process process = new Process
{
StartInfo = startInfo
};
process.OutputDataReceived += new DataReceivedEventHandler(StandardOutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(StandardErrorHandler);
process.Start();
I’ve tried literal strings with and without double quotes, verbatim strings with and without double quotes, and I always get the same error!
What am I doing wrong?!
Thanks
Remove the ” from your arguments string.
It is tricky because the cmd behavior with /C is very strict on the use of ” as can be found out out from cmd /?. If all fails: write your commandline and arguments to a temporary cmd file and start that one…