即使路徑使用雙引號,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