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); } }
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); }