【发布时间】:2015-04-30 16:14:07
【问题描述】:
运行 Git diff 会卡住,直到以 System.Diagnostics.Process 运行时被杀死。
代码:
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;
Process p = new Process();
p.StartInfo = pInfo;
p.Start();
p.WaitForExit(10000);
if (!p.HasExited)
{
p.Kill();
Console.WriteLine("Killed!!!");
}
Console.WriteLine(p.StandardOutput.ReadToEnd());
Console.WriteLine(p.StandardError.ReadToEnd());
Console.ReadLine();
}
}
如何避免这种情况,让程序正常存在而不超时?
【问题讨论】:
-
刚刚在我的机器上用一个 git 项目测试了你的代码,它运行良好。你有更多信息吗?如果在 Git Bash 中运行命令会发生什么。但顺便说一句:安装 git 时,我也选择了能够在命令行中使用 git。
-
我在 Windows 中运行它(所以 .NET,没有 Mono),我添加了“--exit-code”以避免在最后输入“:”以键入“q” (退出)在命令行中运行命令时。但是当从 .NET 运行时,它仍然会卡住。我不知道这是否有帮助。这是任何 Git 配置问题吗?我在网上冲浪和 diff 命令帮助没有成功
-
即使没有 --exit-code,我也不必输入 q 即可退出。该命令在命令行中自动退出。你安装了什么git?来自 git-scm.com 版本?我有 1.9.5 版
-
和你一样的版本。运行命令时,你真的有什么不同吗?否则,该过程可以正常完成。
-
如果我使用命令,我会得到一个文件列表并且命令完成。