1
.Dir이 지정된 exec.Command에 문제가 있습니다. 앱에서 명령을 실행하면 오류가 발생합니다. 하지만 쉘에서 실행하면 동일한 명령이 제대로 작동합니다.golang exec.Command 다른 폴더에 있음
command := exec.Command("git", "rev-parse", "--verify", "tags/v1.0.0^{commit}")
command.Dir = "sub/subdir"
out, err := command.CombinedOutput()
fmt.Printf("Executed command [%s] %s\nErrorCode = %s\nOutput = %s\n", command.Dir, command.Args, err, out)
출력 :
Executed command [sub/subdir] [git rev-parse --verify tags/v1.0.0^{commit}]
ErrorCode = exit status 128
Output = fatal: Needed a single revision
셸 명령 :
내가 잘못 했습니까 무엇$ (cd sub/subdir; git rev-parse --verify tags/v1.0.0^{commit})
c1f3b8707ac001dab875781def3c729e3ed6de2c
?
또는 더 나은 방법으로, 절대 경로를 작성하려면 ['filepath.Abs'] (https://golang.org/pkg/path/filepath/#Abs)를 사용해보십시오. 이 값을 인쇄하여 원하는 경로를 사용하고 있는지 확인하십시오. – cd1
그것은 도움이되지 못했습니다 - 동일한 결과. – Michael