Esempio n. 1
0
        public static ConsoleRedirector CreateRedirector(StreamReader consoleOut, StreamReader errorConsoleOut,
                                                         Process proc, Action <string> del = null)
        {
            ConsoleRedirector gcr = new ConsoleRedirector
            {
                _proc  = proc,
                _cEOut = errorConsoleOut,
                _cOut  = consoleOut,
                _del   = del
            };

            return(gcr);
        }
Esempio n. 2
0
        public static int RunProcess(string file, string args, Action waitAction, Action <string> writeLine = null)
        {
            if (writeLine == null)
            {
                writeLine = Console.WriteLine;
            }

            ProcessStartInfo psi = new ProcessStartInfo(file, args)
            {
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true,
                UseShellExecute        = false
            };

            writeLine(file + " " + args);

            Process p = new Process {
                StartInfo = psi
            };

            p.Start();

            ConsoleRedirector redir;

            redir = ConsoleRedirector.CreateRedirector(p.StandardOutput, p.StandardError, p, writeLine);

            redir.StartThreads();

            while (!p.HasExited)
            {
                waitAction?.Invoke();
            }


            redir.StopThreads();
            writeLine?.Invoke(redir.GetRemainingLogs());

            return(p.ExitCode);
        }