时间:2019-01-17 标签:c#标准输出readtoEnd()
我有以下问题。我运行一个 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);
}
I have the following problem. I run an exe but i can't see in my console application everything that the exe contains. I've expected to see in the console application at least the text i am writing in the running executable. where am i wrong?
1) how can i print in the console application the text that i'm writing in the exe that i run? is that possible? i would also like to use tje standard input stream. I mean I would like to read from the exe and also write in the exe using my application.Here is the code:
Need some help. Thx!
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Standard*
流仅适用于控制台应用程序。您正在运行记事本,它不是控制台应用程序。The
Standard*
streams are only applicable to console applications. You are running notepad, which is not a console application.