我有一个简单的批处理文件:
cd <path to my git repository>
git pull
我尝试使用以下 C# 函数来执行它:
private NuGetBO.ShellCommandReturn ExecuteCommand(string path)
{
ProcessStartInfo processInfo;
Process process;
processInfo = new ProcessStartInfo(path);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
// *** Redirect the output ***
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
process = Process.Start(processInfo);
process.WaitForExit(5000);
// *** Read the streams ***
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
int exitCode = process.ExitCode;
process.Close();
return new NuGetBO.ShellCommandReturn { Error = error, ExitCode = exitCode, Output = output };
}
但我收到以下错误:
"Access is denied.\r\nfatal: Not a git repository (or any of the parent directories): .git\n"
换句话说,我已经尝试从 C# 执行我的批处理文件几个小时但没有成功,但是,如果我在命令行中执行它,我的批处理文件可以正常工作。
如何让我的 C# 函数正常工作,我应该在批处理文件或 C# 函数中更改哪些内容?谢谢
编辑:
我已将批处理文件的内容更改为以下内容:
cd <path to my git repository> && git pull
但我收到以下错误:
Access is denied.
编辑2:
我已添加对该文件夹的访问权限,但现在出现新错误:
fatal: Not a git repository: "../.git/modules/myProject\n"
编辑3:
我已授予 EDIT2 中提到的文件夹的访问权限,但现在收到以下错误:
"error: unable to create directory for C:/myFolder/.git/modules/myProject/ORIG_HEAD\nfatal: Cannot lock the ref 'ORIG_HEAD'.\n"
最佳答案
您需要将 processInfo.WorkingDirectory
设置为 git 存储库的位置。
关于c# - C# 函数执行批处理文件的 Git pull 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13407220/