コード例 #1
0
        internal static int CreateAndStartProcess(string arguments, string cmd, string workDir, out byte[] stdOutput, out byte[] stdError, byte[] stdInput)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                stdOutput = stdError = null;
                return(-1);
            }

            string quotedCmd = cmd;

            if (quotedCmd.IndexOf(' ') != -1)
            {
                quotedCmd = quotedCmd.Quote();
            }
            Settings.GitLog.Log(quotedCmd + " " + arguments);
            //process used to execute external commands

            //data is read from base stream, so encoding doesn't matter
            var startInfo = CreateProcessStartInfo(Encoding.Default);

            startInfo.CreateNoWindow   = true;
            startInfo.FileName         = cmd;
            startInfo.Arguments        = arguments;
            startInfo.WorkingDirectory = workDir;
            startInfo.LoadUserProfile  = true;

            using (var process = Process.Start(startInfo))
            {
                if (stdInput != null && stdInput.Length > 0)
                {
                    process.StandardInput.BaseStream.Write(stdInput, 0, stdInput.Length);
                    process.StandardInput.Close();
                }

                SynchronizedProcessReader.ReadBytes(process, out stdOutput, out stdError);

                process.WaitForExit();

                startInfo = null;
                return(process.ExitCode);
            }
        }
コード例 #2
0
        private static Process StartProcessAndReadAllText(string arguments, string cmd, string workDir, out string stdOutput, out string stdError, string stdInput)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                stdOutput = stdError = "";
                return(null);
            }

            //process used to execute external commands
            var process = StartProcess(cmd, arguments, workDir, GitModule.SystemEncoding);

            if (!string.IsNullOrEmpty(stdInput))
            {
                process.StandardInput.Write(stdInput);
                process.StandardInput.Close();
            }

            SynchronizedProcessReader.Read(process, out stdOutput, out stdError);
            return(process);
        }
コード例 #3
0
        private static Process StartProcessAndReadAllBytes(string arguments, string cmd, string workDir, out byte[] stdOutput, out byte[] stdError, byte[] stdInput)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                stdOutput = stdError = null;
                return(null);
            }

            //process used to execute external commands
            var process = StartProcess(cmd, arguments, workDir, Encoding.Default);

            if (stdInput != null && stdInput.Length > 0)
            {
                process.StandardInput.BaseStream.Write(stdInput, 0, stdInput.Length);
                process.StandardInput.Close();
            }

            SynchronizedProcessReader.ReadBytes(process, out stdOutput, out stdError);

            return(process);
        }
コード例 #4
0
        internal static int CreateAndStartProcess(string arguments, string cmd, string workDir, out string stdOutput, out string stdError, string stdInput)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                stdOutput = stdError = "";
                return(-1);
            }

            string quotedCmd = cmd;

            if (quotedCmd.IndexOf(' ') != -1)
            {
                quotedCmd = quotedCmd.Quote();
            }
            Settings.GitLog.Log(quotedCmd + " " + arguments);
            //process used to execute external commands

            var startInfo = CreateProcessStartInfo(null);

            startInfo.CreateNoWindow   = true;
            startInfo.FileName         = cmd;
            startInfo.Arguments        = arguments;
            startInfo.WorkingDirectory = workDir;
            startInfo.LoadUserProfile  = true;

            using (var process = Process.Start(startInfo))
            {
                if (!string.IsNullOrEmpty(stdInput))
                {
                    process.StandardInput.Write(stdInput);
                    process.StandardInput.Close();
                }

                SynchronizedProcessReader.Read(process, out stdOutput, out stdError);

                process.WaitForExit();
                return(process.ExitCode);
            }
        }