Пример #1
0
        public ProcessOutput Execute(string commandName, string commandArgs)
        {
            ICommandLog commandLog = GetLog().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
            };
        }
Пример #2
0
        public ProcessOutput Execute(string commandName, string commandArgs)
        {
            ICommandLog commandLog = GetLog().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
            });
        }
Пример #3
0
        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;
        }
Пример #4
0
        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);
        }