[英]Prevent Diagnostics.Process to close after finish
I am running prompt commands using this function: 我正在使用此函数运行提示命令:
public static void Execute(string command)
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c " + command,
};
using (Process proc = Process.Start(psi))
proc.WaitForExit();
}
But when the process ends i have no way to see the result of it in the console because it closes instantly. 但是当进程结束时,我无法在控制台中看到它的结果,因为它立即关闭。 Is there a way to prevent this from happening?
有没有办法防止这种情况发生?
Put Console.ReadKey();
把
Console.ReadKey();
at the end of the code: 在代码的末尾:
static void Main(string[] args)
{
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c ",
};
using (Process proc = Process.Start(psi))
proc.WaitForExit();
Console.ReadKey();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.