[英]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.