コード例 #1
0
        public ProcessWrapper StartConsoleProcess(string command, string arguments, string workingDirectory, IConsole console, EventHandler exited)
        {
            if (console == null || (console is ExternalConsole)) {
                string additionalCommands = "";
                if (!console.CloseOnDispose)
                    additionalCommands = @"echo; read -p 'Press any key to continue...' -n1;";
                ProcessStartInfo psi = new ProcessStartInfo("xterm",
                    String.Format (@"-e ""cd {3} ; '{0}' {1} ; {2}""", command, arguments, additionalCommands, workingDirectory));
                psi.UseShellExecute = false;

                if (workingDirectory != null)
                    psi.WorkingDirectory = workingDirectory;

                psi.UseShellExecute  =  false;

                ProcessWrapper p = new ProcessWrapper();

                if (exited != null)
                    p.Exited += exited;

                p.StartInfo = psi;
                p.Start();
                return p;
            } else {
                ProcessWrapper pw = StartProcess (command, arguments, workingDirectory, console.Out, console.Error, null);
                new ProcessMonitor (console, pw, exited);
                return pw;
            }
        }
コード例 #2
0
        public ProcessWrapper StartProcess(string command, string arguments, string workingDirectory, ProcessEventHandler outputStreamChanged, ProcessEventHandler errorStreamChanged, EventHandler exited)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            if (command.Length == 0)
                throw new ArgumentException("command");

            ProcessWrapper p = new ProcessWrapper();

            if (outputStreamChanged != null) {
                p.OutputStreamChanged += outputStreamChanged;
            }

            if (errorStreamChanged != null)
                p.ErrorStreamChanged += errorStreamChanged;

            if (exited != null)
                p.Exited += exited;

            if(arguments == null || arguments.Length == 0)
                p.StartInfo = new ProcessStartInfo (command);
            else
                p.StartInfo = new ProcessStartInfo (command, arguments);

            if(workingDirectory != null && workingDirectory.Length > 0)
                p.StartInfo.WorkingDirectory = workingDirectory;

            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.UseShellExecute = false;
            p.EnableRaisingEvents = true;

            p.Start ();
            return p;
        }