我有以下问题。我运行一个exe文件,但我无法在控制台应用程序中看到exe文件包含的所有内容。我期望在控制台应用程序中看到至少我正在运行的可执行文件中写入的文本。我在哪里错了?c#standard output readtoEnd()
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);
}
您是否期望在控制台中转储您在记事本中编写的文本? – 2011-04-07 09:52:53
您能详细说明您正在尝试做什么吗?为什么你需要一个单独的过程? – GregC 2011-04-07 09:53:40
我不确定Notepad.exe写入标准输出或标准错误......它不是一个命令行程序,它是一个GUI程序。 – 2011-04-07 09:58:15