C# System.Diagnostics.Process redirecting Standard Out for large amounts of data

前端 未结 5 1456
情歌与酒
情歌与酒 2020-12-21 12:51

I running an exe from a .NET app and trying to redirect standard out to a streamreader. The problem is that when I do

myprocess.exe >> out.txt

out.txt is cl

5条回答
  •  心在旅途
    2020-12-21 12:59

    The Process class exposes the stdout stream directly, so you should be able to read it at whatever pace you like. It's probably best to read it in small chunks and avoid calling ReadToEnd.

    For example:

    using(StreamReader sr = new StreamReader(myProcess.StandardOutput))
    {
      string line;
      while((line = sr.ReadLine()) != null)
      {
        // do something with line
      }
    }
    

提交回复
热议问题