查找显示批处理文件输出的C#WinForms应用程序示例

查找显示批处理文件输出的C#WinForms应用程序示例,c#,batch-file,C#,Batch File,我正在寻找一个WinForms应用程序的c#示例项目,它将后台运行的批处理文件的输出重定向到任何类型的WinForms控件 有什么建议吗?我不知道你是否能找到一个直接的例子,但这并不太难。我没有时间为您编写所有代码,但我可以从MSDN中为您提供代码: Process myProcess = new Process(); ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("C:\\MyBatchFile.bat" );

我正在寻找一个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
看这里


它将向您展示如何将输出重定向到事件。然后,您可以将输出放入win控件。

我建议
myStreamReader.ReadToEnd(),但为实心+1.;)@兰斯·梅——我本想在发帖前做些改变的。这就是MSDN最初使用的。我做了更新。