【问题标题】:Is it possible to use a C Sharp console as an external console for an executable run through the program?是否可以将 C Sharp 控制台用作通过程序运行的可执行文件的外部控制台?
【发布时间】:2014-02-12 18:05:40
【问题描述】:

我有一个 C# 程序,我想知道我是否能够通过我的程序启动外部应用程序并使用控制台查看外部应用程序的输出。这在 C# 中可行吗?

【问题讨论】:

  • 如果是控制台应用程序,绝对可以。还有其他问题吗?
  • 你的意思是像 Visual Studio 那样?

标签: c# winforms console external


【解决方案1】:

http://www.dotnetperls.com/redirectstandardoutput:

//
// Setup the process with the ProcessStartInfo class.
//
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\7za.exe"; // Specify exe name.
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
//
// Start the process.
//
using (Process process = Process.Start(start))
{
    //
    // Read in all the text from the process with the StreamReader.
    //
    using (StreamReader reader = process.StandardOutput)
    {
    string result = reader.ReadToEnd();
    Console.Write(result);
    }
}

我自己使用 Houdini ChessEngine 读取 PGN 文件并使用一组给定参数计算棋盘情况(WPF 应用程序)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多