【发布时间】:2021-04-24 06:58:24
【问题描述】:
我通过创建一个新进程从 C# 应用程序调用 git clone,它成功调用了 git,但没有输出返回给我的委托。这意味着随着流程的进行,我无法向用户提供任何更新。 Clone_DataOutputReceived 方法根本没有被调用。
public void CloneRepo(string repoUrl, string dataPath)
{
var process = new Process();
process.StartInfo.FileName = @"git.exe";
process.StartInfo.Arguments = $"clone {repoUrl}";
process.StartInfo.WorkingDirectory = dataPath;
process.OutputDataReceived += Clone_DataOutputReceived;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
process.CancelOutputRead();
}
private void Clone_DataOutputReceived(object sender, DataReceivedEventArgs e)
{
// This method is not being called
// Expecting d.Data to be populated with the line from the output
}
【问题讨论】:
-
您重定向了标准错误,但从未阅读过它?
-
如果检测到交互式控制台 (stackoverflow.com/questions/26056130/git-clone-verbose-output),git 也会更改其输出。