【问题标题】:Calling git clone from C# app doesn't return output data从 C# 应用程序调用 git clone 不会返回输出数据
【发布时间】: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
}

【问题讨论】:

标签: c# git


【解决方案1】:

我认为您想将 FileName 设置为“cmd.exe”,然后向 cmd 实例发出 process.SendCommand("git.exe")。

【讨论】:

  • 进程对象上没有我能够看到的 SendCommand 方法。
猜你喜欢
  • 2020-10-15
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-20
  • 1970-01-01
相关资源
最近更新 更多