即使路径使用双引号,Windows 8上的路径中存在空格时,我在C#中启动进程时出现问题,!C#在Windows 8上使用路径中的空格执行外部进程
下面的代码一直工作正常多年来对我们的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();
我试着和文字字符串没有双引号,逐字字符串与不加双引号,我总是得到同样的错误!
我在做什么错?
感谢
你真的必须首先启动cmd吗? – rene
你可以尝试删除“从你的参数字符串 – rene
我同意在代码示例中,我可能不需要启动cmd,但这是用于启动不一定exe文件的不同工具的通用代码(例如作为Java或脚本程序)我已经测试了一个Java程序,我得到了同样的错误:-( – Atogus