简体   繁体   English

C#标准输出readtoEnd()

[英]c# standard output readtoEnd()

I have the following problem. 我有以下问题。 I run an exe but i can't see in my console application everything that the exe contains. 我运行一个exe,但是在控制台应用程序中看不到该exe包含的所有内容。 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? 1)如何在控制台应用程序中打印我在运行的exe中编写的文本? 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: 我的意思是我想从exe读取并也使用我的应用程序在exe中编写。这是代码:

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);
        }

The Standard* streams are only applicable to console applications. Standard*流仅适用于控制台应用程序。 You are running notepad, which is not a console application. 您正在运行记事本,它不是控制台应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM