Set ProcessStartInfo.RedirectStandardOutputto true- this will redirect all output to Process.StandardOutput, which is a stream you can read to find all output messages:
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = msPath,
RedirectStandardOutput = true,
FileName = msCompiler,
Arguments = "-p {0} -v / {1}"
.StrFormat(
CurrentSetting.CodeSource,
CurrentSetting.CompileTarget)
};
Process p = Process.Start(process);
string output = p.StandardOutput.ReadToEnd();
You can also use the event OutputDataReceivedsimilarly to what @Bharath K describes in your answer.
Similar properties / events for StandardError- you need to set RedirectStandardErrorto true.
source
share