C#Windows窗体的.Net和DOS控制台窗体、控制台、Windows、DOS

2023-09-02 21:38:24 作者:旧城旧梦旧情人≈

我有一个执行的批处理文件的窗口形式。我想要的一切,happends在我的控制台在我的形式传输到面板。我怎样才能做到这一点?如何让我的DOS控制台的comunicate我的Windows窗体面板???

I have a windows form that executes a batch file. I want to transfer everything that happends in my console to a panel in my form. How can I do this? How can my DOS console comunicate with my windows form panel???

感谢

推荐答案

您可以从您的窗体应用程序调用DOS或批处理程序,并将输出重定向到一个字符串:

You can call the DOS or batch program from your Form application and redirect the output to a string:

using (var p = new System.Diagnostics.Process( ))
{
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = PathToBatchFile;
    p.StartInfo.Arguments = args;
    p.Start( );
    string o = p.StandardOutput.ReadToEnd( );
    p.WaitForExit( );
}