【发布时间】:2017-08-14 12:00:45
【问题描述】:
我对分配了 .Dir 的 exec.Command 有疑问。当我从应用程序运行命令时,出现错误。但是如果我从 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
外壳命令:
$ (cd sub/subdir; git rev-parse --verify tags/v1.0.0^{commit})
c1f3b8707ac001dab875781def3c729e3ed6de2c
我做错了什么?
【问题讨论】:
标签: go