process.standardoutput.ReadToEnd() always empty?

前端 未结 4 812
你的背包
你的背包 2020-12-10 04:14

I\'m starting a console application, but when I redirect the standard output I always get nothing!

When I don\'t redirect it, and set CreateNoWindow to

4条回答
  •  一生所求
    2020-12-10 04:39

    You have redirection of standard out disabled. Try changing

    cproc.StartInfo.RedirectStandardOutput = false;
    

    into

    cproc.StartInfo.RedirectStandardOutput = true;
    

    Does the following sample from MSDN work for you?

    // Start the child process.
    Process p = new Process();
    // Redirect the output stream of the child process.
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = "Write500Lines.exe";
    p.Start();
    // Do not wait for the child process to exit before
    // reading to the end of its redirected stream.
    // p.WaitForExit();
    // Read the output stream first and then wait.
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
    

提交回复
热议问题