public ProcessOutput Execute(string commandName, string commandArgs) { ICommandLog commandLog = Log.BeginExecutingCommand(commandName, commandArgs); string commandArgumentsForLogging = commandLog.CommandArgumentsForLogging; var output = new CommandOutputReceiver(commandLog); Process p = CreateProcess(commandName, commandArgumentsForLogging, output); try { RunProcess(p); } catch (Win32Exception win32Ex) { if (win32Ex.NativeErrorCode == 2) { // executable file not found throw new ShellExecutableNotFoundException(commandName); } throw; } commandLog.CommandComplete(p.ExitCode); return new ProcessOutput { ExitCode = p.ExitCode, Output = output.Output, Error = output.Error, ErrorAndOutput = output.ErrorAndOutput }; }
public ProcessOutput Execute(string commandName, string commandArgs) { ICommandLog commandLog = Log.BeginExecutingCommand(commandName, commandArgs); string commandArgumentsForLogging = commandLog.CommandArgumentsForLogging; var output = new CommandOutputReceiver(commandLog); Process p = CreateProcess(commandName, commandArgumentsForLogging, output); try { RunProcess(p); } catch (Win32Exception win32Ex) { if (win32Ex.NativeErrorCode == 2) { // executable file not found throw new ShellExecutableNotFoundException(commandName); } throw; } commandLog.CommandComplete(p.ExitCode); return(new ProcessOutput { ExitCode = p.ExitCode, Output = output.Output, Error = output.Error, ErrorAndOutput = output.ErrorAndOutput }); }
private Process CreateProcess(string commandName, string commandArgumentsForLogging, CommandOutputReceiver output) { var processInfo = new ProcessStartInfo(commandName, commandArgumentsForLogging); processInfo.CreateNoWindow = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; processInfo.UseShellExecute = false; processInfo.ErrorDialog = false; var p = new Process { StartInfo = processInfo }; p.ErrorDataReceived += output.ErrorDataReceived; p.OutputDataReceived += output.OutputDataReceived; return p; }
private Process CreateProcess(string commandName, string commandArgumentsForLogging, CommandOutputReceiver output) { var processInfo = new ProcessStartInfo(commandName, commandArgumentsForLogging); processInfo.CreateNoWindow = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; processInfo.UseShellExecute = false; processInfo.ErrorDialog = false; if (string.IsNullOrEmpty(processInfo.EnvironmentVariables["HOME"])) { processInfo.EnvironmentVariables["HOME"] = Environment.GetEnvironmentVariable("UserProfile"); } var p = new Process { StartInfo = processInfo }; p.ErrorDataReceived += output.ErrorDataReceived; p.OutputDataReceived += output.OutputDataReceived; return p; }
public ProcessOutput Execute(string commandName, string commandArgs) { var commandLog = GetLog().BeginExecutingCommand(commandName, commandArgs); var processInfo = new ProcessStartInfo(commandName, commandLog.CommandArgumentsForLogging); processInfo.CreateNoWindow = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; processInfo.UseShellExecute = false; processInfo.ErrorDialog = true; var p = new Process { StartInfo = processInfo }; var output = new CommandOutputReceiver(commandLog); p.ErrorDataReceived += output.ErrorDataReceived; p.OutputDataReceived += output.OutputDataReceived; try { p.Start(); p.BeginErrorReadLine(); p.BeginOutputReadLine(); p.WaitForExit(); commandLog.CommandComplete(p.ExitCode); return new ProcessOutput { ExitCode = p.ExitCode, Output = output.Output, Error = output.Error, ErrorAndOutput = output.ErrorAndOutput }; } catch (Win32Exception win32Ex) { if (win32Ex.NativeErrorCode == 2) { // executable file not found throw new ShellExecutableNotFoundException(commandName); } throw; } }
private Process CreateProcess(string commandName, string commandArgumentsForLogging, CommandOutputReceiver output) { var processInfo = new ProcessStartInfo(commandName, commandArgumentsForLogging); processInfo.CreateNoWindow = true; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; processInfo.UseShellExecute = false; processInfo.ErrorDialog = false; if (string.IsNullOrEmpty(processInfo.EnvironmentVariables["HOME"])) { processInfo.EnvironmentVariables["HOME"] = Environment.GetEnvironmentVariable("UserProfile"); } var p = new Process { StartInfo = processInfo }; p.ErrorDataReceived += output.ErrorDataReceived; p.OutputDataReceived += output.OutputDataReceived; return(p); }