public ProcessExitInfo ExecuteProcess(string command, string arguments)
{
var processStartInfo = CreateProcessStartInfo(command, arguments);
using (var process = new Process { StartInfo = processStartInfo })
{
var output = new StringBuilder();
var error = new StringBuilder();
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrWhiteSpace(e.Data))
{
error.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
return new ProcessExitInfo
{
ExitCode = process.ExitCode,
OutputMessage = output.ToString(),
ErrorMessage = error.ToString()
};
}
}