I am trying to obtain all the text from the git log command via C# Process.Start.
I need the full output for a tool that i am working on.
The problem I am facing is that UseShellExecute = false ommits some info from the result:
commit 77832ec07a2f96c2151c7a2f6ed0417e7e836eca (HEAD -> master)
Author: xxx yyy <xxx.yyy @zzz.com>
Date: Thu Jul 21 12:28:26 2022 +0300
wip
commit f2cac40abf3d4b0cb2109376a635f9b8bd2ae56a
Author: xxx yyy <xxx.yyy @zzz.com>
Date: Tue Jun 21 16:33:57 2022 +0300
wip
so from this output the (HEAD -> master) part gets ommited if i use UseShellExecute = false and if i use UseShellExecute = true i can't capture the output of the process.
I know it has to do something with the fact that those parts of the output get colored so i also tried running git log --no-color but for no avail.
Method declaration:
private string ExecProcessWait(string path, string arguments, string workingDir)
{
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = path,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
WorkingDirectory = workingDir
},
EnableRaisingEvents = true,
};
var output = string.Empty;
proc.ErrorDataReceived += (s, e) =>
{
if (e.Data != null)
{
output += e.Data;
}
};
proc.OutputDataReceived += (s, e) =>
{
if (e.Data != null)
{
output += $"{e.Data}{Environment.NewLine}";
}
};
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
proc.Dispose();
return output;
}
Code sample:
var output = ExecProcessWait("git.exe", "log", @"Git_repo_dir");
@selvin suggested to try a C# git library so i followed this example (LibGit2Sharp) but sadly the same information is missing from it as well.