/// <summary>
        /// Run command, console window is hidden, wait for exit, redirect output
        /// </summary>
        public static string RunCmd(string cmd, string arguments)
        {
            try
            {
                EnvironmentConfiguration.SetEnvironmentVariables();

                arguments = arguments.Replace("$QUOTE$", "\\\"");

                string output, error;
                using (var process = StartProcessAndReadAllText(arguments, cmd, "", out output, out error, null))
                {
                    process.WaitForExit();
                }

                if (!string.IsNullOrEmpty(error))
                {
                    output += Environment.NewLine + error;
                }

                return(output);
            }
            catch (Win32Exception)
            {
                return(string.Empty);
            }
        }
        internal static Process StartProcess(string fileName, string arguments, string workingDirectory, Encoding outputEncoding)
        {
            EnvironmentConfiguration.SetEnvironmentVariables();

            var executionStartTimestamp = DateTime.Now;

            var startInfo    = CreateProcessStartInfo(fileName, arguments, workingDirectory, outputEncoding);
            var startProcess = Process.Start(startInfo);

            startProcess.EnableRaisingEvents = true;

            void ProcessExited(object sender, EventArgs args)
            {
                startProcess.Exited -= ProcessExited;

                string quotedCmd = fileName;

                if (quotedCmd.IndexOf(' ') != -1)
                {
                    quotedCmd = quotedCmd.Quote();
                }

                var executionEndTimestamp = DateTime.Now;

                AppSettings.GitLog.Log(quotedCmd + " " + arguments, executionStartTimestamp, executionEndTimestamp);
            }

            startProcess.Exited += ProcessExited;

            return(startProcess);
        }
        public IProcess Start(ArgumentString arguments = default, bool createWindow = false, bool redirectInput = false, bool redirectOutput = false, Encoding outputEncoding = null)
        {
            // TODO should we set these on the child process only?
            EnvironmentConfiguration.SetEnvironmentVariables();

            var args = (arguments.Arguments ?? "").Replace("$QUOTE$", "\\\"");

            var fileName = _fileNameProvider();

            return(new ProcessWrapper(fileName, args, _workingDir, createWindow, redirectInput, redirectOutput, outputEncoding));
        }
        internal static Process StartProcess(string fileName, string arguments, string workingDirectory, Encoding outputEncoding)
        {
            EnvironmentConfiguration.SetEnvironmentVariables();

            var startCmd = AppSettings.GitLog.Log(fileName, arguments);

            var startInfo    = CreateProcessStartInfo(fileName, arguments, workingDirectory, outputEncoding);
            var startProcess = Process.Start(startInfo);

            startProcess.EnableRaisingEvents = true;

            void ProcessExited(object sender, EventArgs args)
            {
                startProcess.Exited -= ProcessExited;
                startCmd.LogEnd();
            }

            startProcess.Exited += ProcessExited;

            return(startProcess);
        }
Beispiel #5
0
        internal static Process StartProcess(string fileName, string arguments, string workingDirectory, Encoding outputEncoding)
        {
            EnvironmentConfiguration.SetEnvironmentVariables();

            var operation = CommandLog.LogProcessStart(fileName, arguments);

            var startInfo = CreateProcessStartInfo(fileName, arguments, workingDirectory, outputEncoding);
            var process   = Process.Start(startInfo);

            process.EnableRaisingEvents = true;
            operation.SetProcessId(process.Id);

            void ProcessExited(object sender, EventArgs args)
            {
                process.Exited -= ProcessExited;
                operation.LogProcessEnd();
            }

            process.Exited += ProcessExited;

            return(process);
        }
 /// <summary>
 /// Run command, console window is hidden, wait for exit, redirect output
 /// </summary>
 public static IEnumerable <string> ReadCmdOutputLines(string cmd, string arguments, string workDir, string stdInput)
 {
     EnvironmentConfiguration.SetEnvironmentVariables();
     arguments = arguments.Replace("$QUOTE$", "\\\"");
     return(StartProcessAndReadLines(arguments, cmd, workDir, stdInput));
 }