Пример #1
0
        private Process CreateProcess(string commandName, string commandArgumentsForLogging, IShellLogger 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;
        }
Пример #2
0
        public ProcessOutput Exec(string commandName, string commandArgs, IShellLogger overridingShellLogger = null)
        {
            var stringLogger = new StringShellLogger();
            var logger = new MultiShellLogger(overridingShellLogger ?? new ConsoleShellLogger(), stringLogger);

            var exitCode = Execute(commandName, commandArgs, logger);

            if (exitCode != 0) {
                throw new CommandExecutionException(String.Format("running: {0} {1}\nin: {2}\nexited with {3}", commandName, commandArgs, Directory.GetCurrentDirectory(), exitCode), stringLogger.ErrorAndOutput, exitCode);
            }

            return new ProcessOutput {
                ExitCode = exitCode,
                Error = stringLogger.Error,
                Output = stringLogger.Output,
                ErrorAndOutput = stringLogger.ErrorAndOutput
            };
        }
Пример #3
0
        public ProcessOutput Exec(string commandName, string commandArgs, IShellLogger overridingShellLogger = null)
        {
            var stringLogger = new StringShellLogger();
            var logger       = new MultiShellLogger(overridingShellLogger ?? new ConsoleShellLogger(), stringLogger);

            var exitCode = Execute(commandName, commandArgs, logger);

            if (exitCode != 0)
            {
                throw new CommandExecutionException(String.Format("running: {0} {1}\nin: {2}\nexited with {3}", commandName, commandArgs, Directory.GetCurrentDirectory(), exitCode), stringLogger.ErrorAndOutput, exitCode);
            }

            return(new ProcessOutput {
                ExitCode = exitCode,
                Error = stringLogger.Error,
                Output = stringLogger.Output,
                ErrorAndOutput = stringLogger.ErrorAndOutput
            });
        }
Пример #4
0
        public int Execute(string commandName, string commandArgs, IShellLogger logger)
        {
            Log.Info("in: {0}", Directory.GetCurrentDirectory());
            Log.Info("exec: {0} {1}", commandName, commandArgs);

            Process p = CreateProcess(commandName, commandArgs, logger);

            try
            {
                RunProcess(p);
            }
            catch (Win32Exception win32Ex)
            {
                if (win32Ex.NativeErrorCode == 2)
                { // executable file not found
                    throw new ShellExecutableNotFoundException(commandName);
                }
                throw;
            }

            Log.Info("command: {0}, complete with: {1}", commandName, p.ExitCode);

            return p.ExitCode;
        }
Пример #5
0
        public int Execute(string commandName, string commandArgs, IShellLogger logger)
        {
            Log.Info("in: {0}", Directory.GetCurrentDirectory());
            Log.Info("exec: {0} {1}", commandName, commandArgs);

            Process p = CreateProcess(commandName, commandArgs, logger);

            try
            {
                RunProcess(p);
            }
            catch (Win32Exception win32Ex)
            {
                if (win32Ex.NativeErrorCode == 2)
                { // executable file not found
                    throw new ShellExecutableNotFoundException(commandName);
                }
                throw;
            }

            Log.Info("command: {0}, complete with: {1}", commandName, p.ExitCode);

            return(p.ExitCode);
        }
Пример #6
0
 public ProcessOutput Exec(string command, IShellLogger logger = null)
 {
     return Exec("cmd", "/c " + command);
 }
Пример #7
0
        private Process CreateProcess(string commandName, string commandArgumentsForLogging, IShellLogger 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);
        }
Пример #8
0
 public ProcessOutput Exec(string command, IShellLogger logger = null)
 {
     return(Exec("cmd", "/c " + command));
 }