duannei0044 2016-01-19 01:45
浏览 143
已采纳

用os.exec(“ git”,“ clone”)克隆仓库

Running the code below, I expected the github hosted project username/mysuperrepo to be cloned (once I visit the clone path) into the repo where this go project is running, but it doesn't work. After stopping the application, there's no directory for mysuperrepo no any of the files that I would expect from running git clone https://github.com/username/mysuperrepo.git from the command line

Question: Why wouldn't the code below produce a clone of the repo in the directory where the go program is running?

func clone(w http.ResponseWriter, r *http.Request){
  var repo = "https://github.com/username/mysuperrepo.git"
  exec.Command("git", "clone", repo)
  w.Write([]byte(repo))
}
func main(){
  http.HandleFunc("/clone/", clone)
  log.Fatal(http.ListenAndServe(":8080", nil))
}
  • 写回答

1条回答 默认 最新

  • doushang7209 2016-01-19 10:21
    关注

    You need to call Run to actually execute the command.

    cmd := exec.Command("git", "clone", repo)
    err := cmd.Run()
    if err != nil {
        // something went wrong
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd