【问题标题】:Getting the ouput from Console window into Winform application将控制台窗口的输出输入 Winform 应用程序
【发布时间】:2023-04-10 04:28:01
【问题描述】:

我有一个控制台应用程序,它执行一组操作并在完成每个操作后发出消息。当我运行控制台应用程序时,控制台窗口中的消息可能如下所示:

Checking prerequisites...
Completing prerequisites..
Performing installation...
Completing installation...
Done..!

现在我正在使用 Process.StartInfo() 从我的一个 C# Windows 应用程序中执行此控制台应用程序。 我需要让我的控制台应用程序抛出的所有消息都显示在我的应用程序的窗口形式中。

这个可以吗?

谢谢。

【问题讨论】:

标签: c# winforms console-application


【解决方案1】:
【解决方案2】:

这可以很容易地使用 ProcessStartInfo.RedirectStandardOutput 属性来实现。完整示例包含在链接的MSDN documentation 中。

Process compiler = new Process();
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();    

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

【讨论】:

    猜你喜欢
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    相关资源
    最近更新 更多