c# - 从 C# 应用程序调用 git clone 不会返回输出数据
问题描述
我通过创建一个新进程从 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
}
解决方案
我认为您想将 FileName 设置为“cmd.exe”,然后向 cmd 实例发出 process.SendCommand("git.exe") 。
推荐阅读
- javascript - RequireJS 2个具有依赖关系的模块之间的问题共享方法和变量
- google-cloud-functions - Dialogflow - 从上下文中获取参数
- machine-learning - Vowpal Wabbit 可能的哈希冲突
- c - 在 C 中添加 0101 和 5 背后的逻辑是什么?
- reactjs - 为行返回不同的值
- vb.net-2010 - 在多行文本框中搜索项目,然后检查已检查列表框中的相应项目(如果找到)[VB.NET]
- angular - Redux:一个大动作还是几个小动作?
- android - 应用中病毒,建议卸载应用
- ios - Ionic v3 - 将本地图像转换为 base64
- google-places-api - 调用 Google Place Near By Search api 下一个结果的价格是多少?