Monday, September 29, 2014

Getting the output when running a Process

This is what I tried



Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "StartFTP.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.ReadLine(); //This line will tell me whether it runs successfully or encounter error while running

I can't use ReadToEnd, as the program is continuously listening(FTP Server) and it is not supposed to end


I just want to read the first line to check whether it encounter any error.( I am printing this output in the web interface when I click the button it will execute the above code)


No comments:

Post a Comment