[英]How can I run a command line app in C# and redirect/display its standard output while preserving the colors from the app?
I am calling git via a command line in C#: 我通过C#中的命令行调用git:
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; 但是,当我稍后去向控制台编写重定向的输出时,通常不会显示命令行git app正常显示的颜色。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.