C# Git diff在作为.NET进程运行时被卡住
运行Git diff会被卡住,直到作为C# Git diff在作为.NET进程运行时被卡住,c#,.net,git,C#,.net,Git,运行Git diff会被卡住,直到作为系统运行时被杀死。Diagnostics.Process 代码: 如何避免这种情况并使程序正常存在而不使其超时过期?问题是必须有人使用标准输出缓冲区,否则它将被填满,进程将被阻塞(请参阅说明)。我尝试的diff检索了983行,这导致了缓冲区溢出 以下是我的问题的解决方案: class Program { static void Main(string[] args) { ProcessStart
系统运行时被杀死。Diagnostics.Process
代码:
如何避免这种情况并使程序正常存在而不使其超时过期?问题是必须有人使用标准输出缓冲区,否则它将被填满,进程将被阻塞(请参阅说明)。我尝试的diff检索了983行,这导致了缓冲区溢出 以下是我的问题的解决方案:
class Program
{
static void Main(string[] args)
{
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "git.exe";
pInfo.Arguments = "diff --name-only --exit-code V2.4-Beta-01 HEAD";
pInfo.WorkingDirectory = @"C:\Git";
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardOutput = true;
string output = string.Empty;
Process p = new Process();
p.StartInfo = pInfo;
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (!String.IsNullOrEmpty(e.Data))
{
output += e.Data + Environment.NewLine;
}
});
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
p.Close();
Console.WriteLine(output);
Console.ReadLine();
}
}
刚刚用git项目在我的机器上测试了你的代码,效果很好。你有更多的信息吗?如果在gitbash中运行该命令,会发生什么。但正如旁注:在安装git时,我也选择了在命令行中使用git。我在Windows中运行它(所以.NET,没有Mono),我在命令行中运行命令时,在末尾添加“-exit code”以避免得到“:”以键入“q”(退出)。但是当从.NET运行时,它仍然会被阻塞。我不知道这是否有帮助。这是Git配置的问题吗?我已经浏览过网络和diff命令帮助,但没有成功。即使没有退出代码,我也不必输入q来退出。命令将自动在命令行中退出。你安装了什么git?从git-scm.com版本?我的版本是1.9.5,与您的版本相同。您在运行命令时是否确实存在差异?如果我使用这个命令,我会得到一个文件列表,命令就会完成。
class Program
{
static void Main(string[] args)
{
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName = "git.exe";
pInfo.Arguments = "diff --name-only --exit-code V2.4-Beta-01 HEAD";
pInfo.WorkingDirectory = @"C:\Git";
pInfo.UseShellExecute = false;
pInfo.CreateNoWindow = true;
pInfo.RedirectStandardError = true;
pInfo.RedirectStandardOutput = true;
string output = string.Empty;
Process p = new Process();
p.StartInfo = pInfo;
p.OutputDataReceived += new DataReceivedEventHandler((sender, e) =>
{
if (!String.IsNullOrEmpty(e.Data))
{
output += e.Data + Environment.NewLine;
}
});
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
p.Close();
Console.WriteLine(output);
Console.ReadLine();
}
}