Hello, I'm launching top process in Mono (I know right - herecy) and redirecting it's output to a string (then the parsing will begin). Problem is, that it runs once and quits.
In Linux this code runs flawlessly: http://i.imgur.com/hrB85.jpg
For FreeBSD's top I tried -b, -i, -n, even no arguments, top just prints it's output once and process exits.
Why why why?
In Linux this code runs flawlessly: http://i.imgur.com/hrB85.jpg
Code:
using System;
using System.Diagnostics;
namespace top2
{
class Program
{
static int Main(string[] args)
{
var proc = new ProcessStartInfo("/usr/bin/top", "-b")
{
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
};
using(Process p = Process.Start(proc))
{
try
{
while(p.StandardOutput.Peek() > 0)
{
string line = p.StandardOutput.ReadLine();
//string line2 = p.StandardError.ReadLine() ?? "";
//Console.WriteLine(line);
//if(line2.Length > 0) Console.WriteLine("error: " + line2);
if(line.Contains("Cpu(s):"))
{
Console.WriteLine(line);
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return 0;
}
}
}
Why why why?