public bool RunExternalProcess(IJob job) { Process process = null; try { string prevDir = Directory.GetCurrentDirectory(); if (Directory.Exists(job.WorkingDirectory)) { Directory.SetCurrentDirectory(job.WorkingDirectory); } if (job.Argument == null) { process = new Process() { StartInfo = new ProcessStartInfo(job.Command as string) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = job.WorkingDirectory }, EnableRaisingEvents = true }; } else { process = new Process() { StartInfo = new ProcessStartInfo(job.Command as string, job.Argument as string) { RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, UseShellExecute = false, WorkingDirectory = job.WorkingDirectory }, EnableRaisingEvents = true }; } // see below for output handler if (null != job.StdErrCallBack) { process.ErrorDataReceived += job.StdErrCallBack; } if (null != job.StdOutCallBack) { process.OutputDataReceived += job.StdOutCallBack; } process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); process.WaitForExit(); Directory.SetCurrentDirectory(prevDir); return true; } catch (Exception err) { DataReceivedEventArgs arg = CreateMockDataReceivedEventArgs(err.ToString()); job.StdErrCallBack(this, arg); return false; } }