Contains functions to execute external console applications. Standard streams (stdout/stderr) are captured and returned. Command shell is not invoked as that would prevent capturing the streams. Internally, the invocation is asynchronous.
Example #1
0
        public static ExecResult Run(string gitcmd, bool async)
        {
            // Pick up git commands that take long time to execute and run them
            // using a threaded execution
            if (gitcmd.StartsWith("clone --progress") ||
                gitcmd.StartsWith("fetch") ||
                gitcmd.StartsWith("pull ") ||
                gitcmd.StartsWith("push "))
            {
                FormGitRun formGitRun = new FormGitRun(Properties.Settings.Default.GitPath, gitcmd);
                formGitRun.ShowDialog();
                return formGitRun.GetResult();
            }

            if (!async)
            {
                return Exec.Run(Properties.Settings.Default.GitPath, gitcmd);
            }

            var job = new Exec(Properties.Settings.Default.GitPath, gitcmd);
            job.AsyncRun(s => App.PrintStatusMessage(s, MessageType.Output),
                         s => App.PrintStatusMessage(s, MessageType.Error),
                         null);
            return new ExecResult();
        }
Example #2
0
        /// <summary>
        /// Class constructor that also pre-sets the command and argument to be run
        /// </summary>
        public FormGitRun(string cmd, string args)
        {
            InitializeComponent();
            ClassWinGeometry.Restore(this);

            // WAR: On Linux, remove status bar resizing grip (since it does not work under X)
            if (ClassUtils.IsMono())
                statusStrip.SizingGrip = false;

            job = new Exec(cmd, args);

            // Reuse the same font selected as fixed-pitch
            textStdout.Font = Properties.Settings.Default.commitFont;
            textStdout.Text += cmd + Environment.NewLine;
            textStdout.Text += args + Environment.NewLine;
        }
Example #3
0
        /// <summary>
        /// Main command execution function.
        /// Upon completion, prints all errors to the log window.
        /// </summary>
        public static ExecResult Run(string cmd, string args)
        {
            App.PrintLogMessage(String.Format("Exec: {0} {1}", cmd, args), MessageType.Command);
            App.StatusBusy(true);
            Exec job = new Exec(cmd, args);
            job.Thread = new Thread(job.ThreadedRun);
            job.Thread.Start(10000);
            job.Thread.Join();
            // There are known problems with async output not being flushed as the
            // thread exits. Releasing a time-slice using DoEvents seems to fix
            // the problem in this particular setting.
            Application.DoEvents();
            App.StatusBusy(false);
            if (job.Result.Success() == false)
                App.PrintLogMessage("Error: " + job.Result.stderr, MessageType.Error);

            return job.Result;
        }