2019-07-03 21:06
浏览 174

使用golang exec库将gitconfig参数传递到git bash中

I am trying to write a go script to setup the user's name in the gitconfig file.

I tried the following arguments shown in the code below in the terminal and it works when I manually input the arguments sequentially, but it does not work from golang.

cl := exec.Command("git", "-C", "config", "--global", "", 
stdout, err := cl.CombinedOutput()
if err != nil {
fmt.Printf("%s", stdout)

From the code snippet I expect the code to generate a .gitconfig file and for the file to contain the name of the user. When I run the code I get exit status 128.

图片转代码服务由CSDN问答提供 功能建议


我在终端中的以下代码中尝试了以下参数,并且当我依次手动输入参数时可以使用,但不适用于golang。 \ n

  cl:= exec.Command(“ git”,“ -C”,“ config”,“ --global”,“”,
“ myname”)
stdout,err:  = cl.CombinedOutput()
if err!= nil {

从代码片段中,我希望代码生成一个.gitconfig文件,并使该文件包含用户名。 运行代码时,我的退出状态为128。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqvj51875 2019-07-03 21:20

    You probably shouldn't include the -C option without also giving it a path. If you are trying to add something to the global config, you probably don't need the -C option at all.

    解决 无用
    打赏 举报

相关推荐 更多相似问题