当 Windows 8 上的路径中有空格时,我在 C# 中启动进程时遇到问题,即使路径是双引号!
以下代码在我们的 XP 和 Windows 7 机器上运行良好多年,但我们最近将一些开发框切换到 Windows 8,现在我们收到以下错误:
'D:\Workspace\Visual' is not recognized as an internal or external command, operable program or batch file.
代码:
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();
我试过带和不带双引号的文字字符串,带和不带双引号的逐字字符串,我总是得到同样的错误!
我究竟做错了什么?!
谢谢