有什么方法可以在 Process.Start(..) 期间保持外部命令窗口打开吗?
我有以下运行 bat 文件的代码。 然后bat文件运行一些.exe..它会做一些事情。 整个过程大约需要 5-10 秒。
ProcessStartInfo start = new ProcessStartInfo
{
Arguments = "\"" + newTargetFile + "\"" +
" " +
"\"" + originalFile.FullName + "\"",
FileName = filename,
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = false,
UseShellExecute = false
};
// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
}
我想做的是让命令窗口保持打开状态,即使在进程终止后也是如此。 有什么办法可以做到这一点吗?
否则,我可以将该窗口的所有输出发送到我的调试器,这样我就不必担心该窗口的剩余情况吗?
干杯。
i've got the following code which runs a bat file. the bat file then runs some .exe .. which does some stuff. The stuff takes aroun 5-10 seconds.
ProcessStartInfo start = new ProcessStartInfo
{
Arguments = "\"" + newTargetFile + "\"" +
" " +
"\"" + originalFile.FullName + "\"",
FileName = filename,
WindowStyle = ProcessWindowStyle.Normal,
CreateNoWindow = false,
UseShellExecute = false
};
// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
}
What i'm trying to do is leave the command window open, even after the process terminates. Is there any way to do this?
Otherwise, can i get all the output of that window going to my debugger instead, so i don't need to worry about this window remaining?
cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 /k 参数运行 cmd 解释器并传入批处理文件名作为下一个参数,您应该得到您想要的结果。 /k 参数告诉 Windows 在完成您作为下一个参数指定的操作后让 cmd 解释器保持打开状态。
您当然也可以使用 RedirectStandardOutput 属性,但我认为最终会更复杂。
If you run the cmd interpreter with a /k argument and pass in the batch file name as the next argument, you should get what you're after. The /k argument tells Windows to leave the cmd interpreter open when it's done with whatever you tell it to do as the next argument.
You could certainly also use the RedirectStandardOutput property, but I think that would be more complicated in the end.
尝试使用 /k 参数来保持终端打开:
Try something like this with a /k argument to keep open the terminal: