exec.Command()返回一个type值
*exec.Cmd。
Cmd是一个struct并具有一个
Dir字段:
// Dir specifies the working directory of the command.// If Dir is the empty string, Run runs the command in the// calling process's current directory.Dir string
因此,只需在调用之前进行设置
Cmd.Output():
cmd:= exec.Command("git", "log")cmd.Dir = "your/intended/working/directory"out, err := cmd.Output()
另请注意,这特定于
git命令;
git允许您使用该
-C标志传递路径,因此您也可以这样 *** 作:
out, err := exec.Command("git", "-C", "your/intended/working/directory", "log"). Output()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)