2012-11-15 2 views
2

을 실행 : 나는 다음과 같은 C#을 기능을 실행하려고힘내 풀 문제 C#을 기능 나는 간단한 배치 파일이 배치 파일

cd <path to my git repository> 
git pull 

:

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 번호에서 내 배치 파일을 실행하도록 내 배치 파일에 법과를 시도했다 ks 명령 줄에서 실행하면 아무런 문제가 없습니다.

어떻게 C# 함수가 작동하도록 할 수 있습니까? 배치 파일이나 C# 함수에서 무엇을 변경해야합니까? 감사합니다

편집 :

cd <path to my git repository> && git pull 

그러나 나는 다음과 같은 오류가 나타납니다 : 나는에 배치 파일의 내용을 변경 한

다음

Access is denied. 

EDIT2 :

I을 폴더에 대한 액세스를 추가했는데 이제는 새로운 오류가 발생합니다 :

fatal: Not a git repository: "../.git/modules/myProject\n" 

EDIT3 : 내가 EDIT2에서 언급 한 폴더에 대한 액세스 권한을 부여했지만, 지금은 다음과 같은 오류가 나타납니다

: 당신은 자식의 위치를 ​​processInfo.WorkingDirectory를 설정해야합니다

"error: unable to create directory for C:/myFolder/.git/modules/myProject/ORIG_HEAD\nfatal: Cannot lock the ref 'ORIG_HEAD'.\n" 
+0

을 도울 수있는 당신을 위해 바보 (? 아마) 질문 : 당신은 경로가 동일한 100 % 확실 해요? –

+0

예, 확실합니다.하지만 버그가있을 수 있으므로 기본 사항을 질문하는 것은 결코 바보가 아닙니다. –

답변

1

이제 작동합니다. 내가 가진 것과 똑같은 신경 쇠약 문제를 가지지 않으려면 앞으로해야 할 사람이 다음을 확인해야합니다. C# 코드를 실행하는 사용자가 있습니다. User으로 전화를 걸면됩니다.

1. User must have privileges to the folder where the git pull should be running. 
2. User must have privileges to the folder where the git repository is located (its path is described in the .git file located in the folder described at 1.) 
1

을 repo.

+0

"디렉토리 이름이 유효하지 않습니다" –

+0

배치 파일은 git 저장소와 다른 위치에 있습니다. –

+0

그리고 무엇? 왜 그것이 무효입니까? – SLaks

1

는 전체 라이브러리를 통합 할 관심이 있다면 아마 여기 this one