0

I've done a git pull origin develop with help of System.Diagnosticsc.Process like this:

var gitProcess = new Process
{ 
    StartInfo = new ProcessStartInfo
    {
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true,
        FileName = "git.exe",
        Arguments = "pull origin develop",
        WorkingDirectory = @"C:\Workspaces\MyRepo",
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden
    }
};
gitProcess.Start();
string outputString = null;
string errorString = null;
gitProcess.OutputDataReceived += (sender, args) => outputString = string.IsNullOrWhiteSpace(outputString) ? args.Data : $"{outputString}\r\n{args.Data}";
gitProcess.ErrorDataReceived += (sender, args) => errorString = string.IsNullOrWhiteSpace(errorString) ? args.Data : $"{errorString}\r\n{args.Data}";

gitProcess.BeginErrorReadLine();
gitProcess.BeginOutputReadLine();
gitProcess.WaitForExit();

The Result is:

gitProcess.ExitCode = 0

outputString = Already up to date.

errorString = From https://mycompany.visualstudio.com/MyProject/_git/MyRepo * branch develop -> FETCH_HEAD

Now every thing seems okay, but why did the the git.exe put the data into the errorString? It seems like normal information. This makes errorhandling hard. The ExitCode is fine it suggests success.

Any ideas why there is errordata, this happens for several other git - commands in a similar manner.

EXPECTED ANSWER

I don't want to hear about alternatives to do a git-pull in c# that's not my interest. I want to understand the behaviour of the git.exe respectivly the behaviour of System.Diagnostics.Process, basically I want to understand how and why that errordata is produced. Who is responsible for that? Is it the git.exe or the way how System.Diagnostics.Process is doing stuff.

Thank you.

Daniel
  • 486
  • 4
  • 19

1 Answers1

0

Thank you for your comments, that helped. I especially researched for the main idea of stdout and stderr. The idea of stderr seems not to be only print error messages when the command failes but also to print any diagnostic information that may help understand the process but you may not want that to have in standard output.

This article explains it very well: https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

Thank you guys!

Daniel
  • 486
  • 4
  • 19