示例#1
0
文件: Shell.cs 项目: joshski/bounce
        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
            };
        }
示例#2
0
文件: Shell.cs 项目: dlsteuer/bounce
        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
            });
        }
示例#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;

            var p = new Process { StartInfo = processInfo };

            p.ErrorDataReceived += output.ErrorDataReceived;
            p.OutputDataReceived += output.OutputDataReceived;
            return p;
        }
示例#4
0
文件: Shell.cs 项目: joshski/bounce
        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;
        }
示例#5
0
        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;
            }
        }
示例#6
0
文件: Shell.cs 项目: dlsteuer/bounce
        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);
        }