简体   繁体   中英

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. 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. Is there a way I can make the CMD window display what it is doing? 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. In effect you are telling Windows that you don't want the output to go to the console window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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