2

Can I get output of existing proccess? When I'm trying it says process is not running or doesn't have output redirect. Example I launched ping google.com -t (waited 20 seconds to have ouput) and I want last 10 lines from it:

var processes = Process.GetProcessesByName("PING").FirstOrDefault(); 
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
process.BeginOutputReadLine();

Any ideas how I can get it?

Andrian Durlestean
  • 1,730
  • 1
  • 19
  • 30
  • I am not sure if that is possible without launching the program you are wanting to monitor in some kind of "special way", if it was started by just typing it's name in a console window I just don't know how to do it. – Scott Chamberlain May 15 '14 at 13:36

1 Answers1

-1

Try:

process.StartInfo.UseShellExecute = false;
process.Start();
process.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
process.BeginOutputReadLine();
apomene
  • 14,282
  • 9
  • 46
  • 72