gpt4 book ai didi

c# - 寻找显示批处理文件输出的 C# WinForms 应用示例

转载 作者:太空狗 更新时间:2023-10-30 00:46:32 25 4
gpt4 key购买 nike

我正在寻找一个 WinForms 应用程序的 C# 示例项目,它将后台运行的批处理文件的输出重定向到任何类型的 WinForms 控件。

有什么建议吗?

最佳答案

我不知道您是否会找到一个直接的示例,但这并不过分困难。我没有时间为您编写所有代码,但我可以为您提供来自 MSDN 的代码:

Process myProcess = new Process();

ProcessStartInfo myProcessStartInfo =
new ProcessStartInfo("C:\\MyBatchFile.bat" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;

myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();

StreamReader myStreamReader = myProcess.StandardOutput;

// Read the standard output of the spawned process.
string myString = myStreamReader.ReadToEnd();

myProcess.Close();

// Now you have the output of the batch file in myString

关于c# - 寻找显示批处理文件输出的 C# WinForms 应用示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3070812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com