我有一个控制台应用程序,它启动另外两个控制台应用程序(不是用 C# 编写的)。
我可以将应用程序的输出定向到应用程序的同一个 CMD 窗口吗?
或者甚至只是禁止它们显示?
最佳答案
对这两个问题都是肯定的 - 您可以重定向输出并阻止它们显示。
看看ProcessStartInfo
类 - 将其传递到 Process
的构造函数中类以确保它按照您想要的方式启动。
var psi = new ProcessStartInfo("path to exe to run");
// ensure output is redirected
// several options to read - using the StandardOutput stream of the process
// another option is to hook up the OutputDataReceived event
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
// ensure no window
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden; // requires UseShellExecute = false
关于c# - 在我的应用程序中嵌入控制台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8771918/