dongshi6844
2019-05-23 10:48
浏览 487

带有Go中参数的exec命令?

In my shell, I can exec command acme.sh --issue --dns -d exmaple.com --yes-I-know-dns-manual-mode-enough-go-ahead-please and get output.

now I want to do that in go, and my code like:

cmd := exec.Command("bash", "-c", "acme.sh --issue --dns -d exmaple.com --yes-I-know-dns-manual-mode-enough-go-ahead-please");
out, err := cmd.CombinedOutput()
if err != nil {
    log.Fatalf("issue failed with error: %s
", err)
}
fmt.Printf("combined out:
%s
", string(out))

but I got error exit status 1.

and as the comment said, I separate argument:

exec.Command("bash", "-c", "acme.sh", "--issue", "--dns", "-d exmaple.com", "--yes-I-know-dns-manual-mode-enough-go-ahead-please");

but the result is that it exec acme.sh without parameters.

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

在我的shell中,我可以执行命令 acme.sh --issue --dns -d exmaple。 com-是的,我知道dns-manual-mode-足够前进了并获取输出。

现在我想继续进行操作, 和我的代码一样:

  cmd:= exec.Command(“ bash”,“-c”,“ acme.sh --issue --dns -d exmaple.com  --yes-I-nnow-dns-manual-mode-go-a-ahead-please“); 
out,err:= cmd.CombinedOutput()
if err!= nil {
 log.Fatalf(” issue 失败并出现错误:%s 
“,err)
} 
fmt.Printf(” combined out:
%s 
“,string(out))
   
 \  n 

,但我得到错误的退出状态1

,正如评论所说,我将参数分开:

exec.Command(“ bash”,“-c”,“ acme.sh”,“-issue”,“-dns”,“-d exmaple.com”,“-是-I- 知道dns-manual-mode-足够前进了,请“);

,但是结果是它执行了 acme.sh 没有参数。

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

2条回答 默认 最新

相关推荐 更多相似问题