【发布时间】:2014-02-12 18:05:40
【问题描述】:
我有一个 C# 程序,我想知道我是否能够通过我的程序启动外部应用程序并使用控制台查看外部应用程序的输出。这在 C# 中可行吗?
【问题讨论】:
-
如果是控制台应用程序,绝对可以。还有其他问题吗?
-
你的意思是像 Visual Studio 那样?
标签: c# winforms console external
我有一个 C# 程序,我想知道我是否能够通过我的程序启动外部应用程序并使用控制台查看外部应用程序的输出。这在 C# 中可行吗?
【问题讨论】:
标签: c# winforms console external
如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 应用程序)。
【讨论】: