【发布时间】:2011-04-07 09:48:06
【问题描述】:
我有以下问题。我运行一个 exe,但在我的控制台应用程序中看不到 exe 包含的所有内容。我希望至少在控制台应用程序中看到我正在运行的可执行文件中编写的文本。我哪里错了?
1) 如何在控制台应用程序中打印我在运行的 exe 中编写的文本?那可能吗?我也想使用 tje 标准输入流。我的意思是我想从 exe 中读取并使用我的应用程序写入 exe。这里是代码:
需要帮助。谢谢!
static void Main(string[] args)
{
string s;
ProcessStartInfo p = new ProcessStartInfo();
p.UseShellExecute = false;
p.RedirectStandardOutput = true;
p.RedirectStandardInput = true;
p.RedirectStandardError = true;
p.FileName = @"notepad.exe";
using (Process pp = Process.Start (p))
{
string output = pp.StandardOutput.ReadToEnd();
//pp.WaitForExit();
StreamReader myStreamReader = pp.StandardError;
// finally output the string
Console.WriteLine("output is: "+output+"....."+myStreamReader.ReadLine());
// pp.Close();
Thread.Sleep (2000);
}
【问题讨论】:
-
您是否希望将您在记事本中编写的文本转储到控制台中?
-
能否请您详细说明您要做什么,确切地说。为什么需要单独的流程?
-
我不确定 Notepad.exe 会写入标准输出还是标准错误...它不是命令行程序,它是 GUI 程序。
标签: c# .net process console-application