我的exec.Command有问题,并且已分配.Dir。当我从应用程序运行命令时,我收到一个错误。但如果我从shell运行它,相同的命令工作正常。
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
Shell命令:
$ (cd sub/subdir; git rev-parse --verify tags/v1.0.0^{commit})
c1f3b8707ac001dab875781def3c729e3ed6de2c
我做错了什么?