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

前端 未结 5 1452
情歌与酒
情歌与酒 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 13:08

    This worked out for me:

                var sb = new StringBuilder();
                while (!proc.StandardOutput.EndOfStream)
                {
                    sb.Append(proc.StandardOutput.ReadToEnd());
                    proc.StandardOutput.DiscardBufferedData();
                }
    

提交回复
热议问题