public void ExecuteSync(string fileName, string arguments, string workingDirectory)
{
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException("fileName");
var process = new Process {
StartInfo = {
FileName = fileName,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory
},
};
process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
process.Exited += Process_Exited;
try {
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
} catch (Win32Exception) {
throw new ExecuteFileNotFoundException(fileName);
}
}