2

我确实有一个奇怪的问题:我尝试调用 git.exe 通过一个小的 c# console-application-> 克隆一个存储库

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 密码)的存储库时,不会触发任何事件,因此我无法以编程方式对该输入做出反应。有没有办法真正获得所有命令输出?

谢谢!

4

1 回答 1

0

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

git clone https://username:password@github.com/username/repository.git
于 2012-11-17T13:51:07.753 回答