我試圖用C#中的參數執行命令行程序。我會想象,在C#中站起來並做到這一點將是微不足道的,但即使擁有本站和其他站點上的所有可用資源,它仍然具有挑戰性。我很茫然,所以我會盡可能提供更多細節。使用C#中的參數執行命令行.exe。
我目前的方法和代碼如下,在調試器中,變量命令具有以下值。
command = "C:\\Folder1\\Interfaces\\Folder2\\Common\\JREbin\\keytool.exe -import -noprompt -trustcacerts -alias myserver.us.goodstuff.world -file C:\\SSL_CERT.cer -storepass changeit -keystore keystore.jks"
問題可能是我如何調用和格式化該變量命令中使用的字符串。
有什麼想法可能是這個問題?
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = procStartInfo;
process.Start();
string result = process.StandardOutput.ReadToEnd();
Console.WriteLine(result);
一旦完成變量結果,我就不會收到任何信息或錯誤。
你在命令行中嘗試這個命令?也許你需要將'command'字符串換成雙引號。你真的得到了什麼錯誤? –
我可以在命令行中成功運行確切的命令。也許這些步驟略有不同,因爲我將目錄設置爲C:\ Folder1 \ Interfaces \ Folder2 \ Common \ JREbin \,然後執行keytool.exe -import -noprompt -trustcacerts -alias myserver.us.goodstuff.world -file C:\ SSL_CERT.cer -storepass changeit -keystore keystore.jks當這個運行時,我收到沒有錯誤,不幸的是控制檯字符串是空的。 –