CreateProcessStartInfo() public static method

public static CreateProcessStartInfo ( string fileName, string arguments, string workingDirectory, Encoding outputEncoding ) : ProcessStartInfo
fileName string
arguments string
workingDirectory string
outputEncoding System.Text.Encoding
return System.Diagnostics.ProcessStartInfo
Exemplo n.º 1
0
        public Process CmdStartProcess(string cmd, string arguments, string workingDir)
        {
            try
            {
                GitCommandHelpers.SetEnvironmentVariable();

                var ssh = GitCommandHelpers.UseSsh(arguments);

                Kill();

                Settings.GitLog.Log(cmd + " " + arguments);

                //process used to execute external commands
                var process = new Process {
                    StartInfo = GitCommandHelpers.CreateProcessStartInfo(null)
                };
                process.StartInfo.CreateNoWindow   = (!ssh && !Settings.ShowGitCommandLine);
                process.StartInfo.FileName         = cmd;
                process.StartInfo.Arguments        = arguments;
                process.StartInfo.WorkingDirectory = workingDir;
                process.StartInfo.WindowStyle      = ProcessWindowStyle.Normal;
                process.StartInfo.LoadUserProfile  = true;
                if (SetupStartInfoCallback != null)
                {
                    SetupStartInfoCallback(process.StartInfo);
                }
                process.EnableRaisingEvents = true;

                if (!StreamOutput)
                {
                    process.OutputDataReceived += ProcessOutputDataReceived;
                    process.ErrorDataReceived  += ProcessErrorDataReceived;
                }
                Output      = new StringBuilder();
                ErrorOutput = new StringBuilder();

                process.Exited += ProcessExited;
                process.Start();
                lock (processLock)
                {
                    myProcess = process;
                }
                if (!StreamOutput)
                {
                    process.BeginErrorReadLine();
                    process.BeginOutputReadLine();
                }

                return(process);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error running command: '" + cmd + " " + arguments, ex);
            }
        }
        public Process CmdStartProcess(string cmd, string arguments)
        {
            try
            {
                GitCommandHelpers.SetEnvironmentVariable();

                var ssh = GitCommandHelpers.UseSsh(arguments);

                Kill();

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

                var executionStartTimestamp = DateTime.Now;

                // process used to execute external commands
                var process   = new Process();
                var startInfo = GitCommandHelpers.CreateProcessStartInfo(cmd, arguments, WorkingDirectory, GitModule.SystemEncoding);
                startInfo.CreateNoWindow = (!ssh && !AppSettings.ShowGitCommandLine);
                process.StartInfo        = startInfo;

                process.EnableRaisingEvents = true;
                process.OutputDataReceived += ProcessOutputDataReceived;
                process.ErrorDataReceived  += ProcessErrorDataReceived;
                process.Exited += ProcessExited;

                process.Exited += (sender, args) =>
                {
                    var executionEndTimestamp = DateTime.Now;
                    AppSettings.GitLog.Log(quotedCmd + " " + arguments, executionStartTimestamp, executionEndTimestamp);
                };

                process.Start();
                lock (_processLock)
                {
                    _myProcess = process;
                }

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                return(process);
            }
            catch (Exception ex)
            {
                ex.Data.Add("command", cmd);
                ex.Data.Add("arguments", arguments);
                throw;
            }
        }
Exemplo n.º 3
0
        public Process CmdStartProcess(string cmd, string arguments)
        {
            try
            {
                GitCommandHelpers.SetEnvironmentVariable();

                var ssh = GitCommandHelpers.UseSsh(arguments);

                Kill();

                string quotedCmd = cmd;
                if (quotedCmd.IndexOf(' ') != -1)
                {
                    quotedCmd = quotedCmd.Quote();
                }
                Settings.GitLog.Log(quotedCmd + " " + arguments);

                //process used to execute external commands
                var process = new Process {
                    StartInfo = GitCommandHelpers.CreateProcessStartInfo(null)
                };
                process.StartInfo.CreateNoWindow   = (!ssh && !Settings.ShowGitCommandLine);
                process.StartInfo.FileName         = cmd;
                process.StartInfo.Arguments        = arguments;
                process.StartInfo.WorkingDirectory = WorkingDirectory;
                process.StartInfo.WindowStyle      = ProcessWindowStyle.Normal;
                process.StartInfo.LoadUserProfile  = true;
                if (SetupStartInfoCallback != null)
                {
                    SetupStartInfoCallback(process.StartInfo);
                }
                process.EnableRaisingEvents = true;

                if (!StreamOutput)
                {
                    process.OutputDataReceived += ProcessOutputDataReceived;
                    process.ErrorDataReceived  += ProcessErrorDataReceived;
                }
                Output      = new StringBuilder();
                ErrorOutput = new StringBuilder();

                process.Exited += ProcessExited;
                process.Start();
                lock (_processLock)
                {
                    _myProcess = process;
                }
                if (!StreamOutput)
                {
                    process.BeginErrorReadLine();
                    process.BeginOutputReadLine();
                }

                return(process);
            }
            catch (Exception ex)
            {
                ex.Data.Add("command", cmd);
                ex.Data.Add("arguments", arguments);
                throw;
            }
        }