I am trying to get the output of the process line by line, but I am getting null value being returned. Can you please check my below code and let me know what wrong am doing here? Please suggest
Process process = new Process();
process.StartInfo.FileName = dirPath + "\\test.exe";
process.StartInfo.Arguments = "-a -h -s " + dir;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
using (StreamReader streamReader = Process.StandardOutput)
{
string line = streamReader.ReadLine();
while (line != null)
{
Console.WriteLine(line);
}
}
process.WaitForExit();
If I use string line = streamReader.ReadToEnd()
it displays all the lines.