110,536
社区成员
发帖
与我相关
我的任务
分享
int count = 0;
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if(e.Data != null)
++count;
}
void Run()
{
Process p = new Process();
p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
p.StartInfo.Arguments = "rev-list HEAD";
p.StartInfo.WorkingDirectory = @"project-path";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += p_OutputDataReceived;
count = 0;
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
Console.WriteLine(count);
}
有两处错误,e.Data有可能是空的,不应该记录
另外要指定一下WorkingDirectory,就是你版本库的位置
版本就是你分支的名称 int count = 0;
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
++count;
}
void Run()
{
Process p = new Process();
p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
p.StartInfo.Arguments = "rev-list HEAD";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.OutputDataReceived += p_OutputDataReceived;
count = 0;
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
Console.WriteLine(count);
}