如何隐藏 git-bash.exe并在通过 C# 进程调用 git 克隆时在后台运行它?



你好,我有以下代码

string newDist = destination + "/" + fileName;
var o = new Process
{
StartInfo = 
{
FileName = pathToGitClient,
Arguments = $"-c "eval $(ssh-agent) && ssh-add {privateKey} && git clone {repoUrl} {repoDest}""
}
};
o.Start();

这基本上是在我的 git 文件夹中使用 git-bash 创建一个 git 克隆进程.exe。如果我想在克隆时隐藏命令行窗口,我将如何做到这一点?

我试过了

o.StartInfo.UseShellExecute = false;
o.StartInfo.CreateNoWindow = true;

但它没有用

您可以使用StartInfo.WindowStyle,它采用 ProcessWindowStyle 枚举的实例。

o.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
// or
o.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

您仍然需要将UseShellExecute设置为false才能正常工作。

最新更新