【问题标题】:How do i hide git-bash.exe and just run it in the background whilst I'm calling a git clone through a C# process?当我通过 C# 进程调用 git clone 时,如何隐藏 git-bash.exe 并在后台运行它?
【发布时间】:2017-07-06 13:30:05
【问题描述】:

您好,我有以下代码

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.exe 创建了一个 git clone 进程。如果我想在克隆时隐藏命令行窗口,我该怎么做?

我试过了

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

但是没用

【问题讨论】:

    标签: c# git bash github process


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-15
      • 2022-08-18
      • 2023-03-29
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      相关资源
      最近更新 更多