简体   繁体   English

使用C#调用.bat文件时,如何使cmd窗口显示批处理文件在做什么?

[英]When calling a .bat file using C#, how can I make the cmd window show what the batch file is doing?

I'm using a Windows form I created in C# to execute a batch file. 我正在使用在C#中创建的Windows窗体来执行批处理文件。 The batch file runs, and the cmd window appears, but the window is blank and does not display any of the commands the batch file is executing. 批处理文件运行,并且显示cmd窗口,但是该窗口为空白,并且不显示该批处理文件正在执行的任何命令。 Is there a way I can make the CMD window display what it is doing? 有什么方法可以使CMD窗口显示正在执行的操作吗? Relevant code snippet below. 相关代码段如下。

var processInfo = new ProcessStartInfo("cmd.exe", "/c " + "\"C:\\tf_Test2.bat\"");
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.WaitForExit();

Change UseShellExecute to true and drop support for redirecting the output streams. UseShellExecute更改为true并删除对重定向输出流的支持。 In effect you are telling Windows that you don't want the output to go to the console window. 实际上,您是在告诉Windows您不希望输出进入控制台窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM