I am calling git via a command line in C#:
var logger = CreateProcess("git", $"log -n 1 {branchName}");
// some more code here
Console.WriteLine(logger.StandardOutput.ReadToEnd());
private static Process CreateProcess(string exe, string args)
{
var p = new Process();
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
return p;
}
However the colors that are normally displayed by the command line git app are not displayed when I later go to write the redirected output ot the console; everything is white instead. Is there any way to run the app and redirect the output without losing the colors?
git -c color.ui=always log
参见https://git-scm.com/docs/git-config#Documentation/git-config.txt-colorui
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.