internal void Run()
{
try
{
var procInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardError = _captureOutput,
RedirectStandardOutput = _captureOutput,
FileName = _program,
CreateNoWindow = true,
Arguments = GetArgumentString()
};
using (var process = Process.Start(procInfo))
{
if (_captureOutput)
{
var stdOut = new StringBuilder();
var stdErr = new StringBuilder();
while (process != null && !process.HasExited)
{
stdOut.Append(process.StandardOutput.ReadToEnd());
stdErr.Append(process.StandardError.ReadToEnd());
}
if (process != null)
{
stdOut.Append(process.StandardOutput.ReadToEnd());
stdErr.Append(process.StandardError.ReadToEnd());
}
Output = stdOut.ToString().Trim(Environment.NewLine.ToCharArray()).Trim('\r', '\n');
Error = stdErr.ToString().Trim(Environment.NewLine.ToCharArray()).Trim('\r', '\n');
}
Exception = null;
}
}
catch (Exception ex)
{
Output = null;
Error = ex.Message;
Exception = ex;
}
}