[英]Running an exe from with another exe C# and closing it
我正在嘗試在C#中的另一個exe文件中運行一個exe文件
那很好,但是我的問題是應該在另一個內部運行的exe打開另一個控制台窗口,我需要在其中按下“ Enter”,以使其在完成操作后停止。
有沒有辦法做到這一點?
這是我到目前為止的代碼。
var proc = new Process();
proc.StartInfo.FileName = "thefile.exe";
proc.Start();
proc.WaitForExit();
var exitCode = proc.ExitCode;
proc.Close();
謝謝
只需使用cmd打開並終止exe /用戶窗口即可。
string executingCommand;
executingCommand= "/C Path\\To\\Your\\.exe"; // the /C terminates after carrying out the command
System.Diagnostics.Process.Start("CMD.exe", executingCommand);
是否在尋找輸入重定向 ?
int exitCode = -1;
// Put IDisposable into using
using (var proc = new Process()) {
proc.StartInfo.FileName = "thefile.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.Start();
using (StreamWriter inputWriter = proc.StandardInput) {
inputWriter.Write('\n');
}
proc.WaitForExit();
exitCode = proc.ExitCode;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.