【问题标题】:OutputDataReceived does not work with windows git.exeOutputDataReceived 不适用于 windows git.exe
【发布时间】:2012-10-24 11:02:55
【问题描述】:

我确实有一个奇怪的问题:我尝试调用 git.exe 通过一个小的 c# 控制台应用程序克隆一个存储库->

Process p = new Process();
p.StartInfo.FileName = "path/to/git/git.exe";
p.StartInfo.Arguments = "clone SomeGitRepoWhichRequiresPassword";
p.StartInfo.UseShellExecute = false;
p.EnableRaisingEvents = true;

p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardError = true;

p.OutputDataReceived += OutputDataReceived;
p.ErrorDataReceived += ErrorDataReceived;
p.Exited += Exited;

p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();

当我尝试克隆需要用户输入(例如输入 ssh 密码)的存储库时,不会触发任何事件,因此我无法以编程方式对该输入做出反应。有没有办法真正获得所有命令输出?

谢谢!

【问题讨论】:

    标签: c# .net console


    【解决方案1】:

    为什么要以编程方式输入密码?您可以尝试在 Git 存储库 URL 中写入密码,如下所示:

    git clone https://username:password@github.com/username/repository.git
    

    【讨论】:

    • 感谢您的回答。但是通过 ssh 克隆一个 repo 呢?一些 repos 只能通过 ssh 访问...
    • 我认为以编程方式使用 git 存储库的更好方法是 libgit2 (libgit2.github.com)
    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多