[英]C# Change folder and start process in CMD, wait for it to finish
我需要從Windows窗體應用程序打開一個外部進程。 更重要的是,我需要在應用運行時執行幾次。 基本上,我正在命令提示符下多次執行帶有參數的.exe文件,但是我需要將文件夾更改為.exe所在的位置,以使其正常工作。 到目前為止,我像這樣打開cmd:
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
Process process = Process.Start(processStartInfo);
然后使用process.WriteLine將命令輸入到CMD。
process.StandardInput.WriteLine("Awin.exe -X " + filePath + "/" + fileNumber + " ID=\"" + id + "\"");
我需要對幾個fileNumber文件執行此操作。 另外,我需要等待從輸入開始的過程結束,然后再繼續下一個過程。 是否有更好的方法來執行此操作,因為使用process.WaitForExit無法獲得良好的結果
ProcessStartInfo
類具有WorkingDirectory
屬性。
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.WorkingDirectory = your_directory
(...)
//do your thing
Process process = Process.Start(processStartInfo);
可以通過Arguments
屬性傳遞Arguments
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.