为了账号安全,请及时绑定邮箱和手机立即绑定

在 Windows 上使用 exec.Command 进行 noverify

在 Windows 上使用 exec.Command 进行 noverify

Go
慕莱坞森 2023-07-17 16:45:14
我想使用VKCOM/ noverify来分析代码。使用此命令从命令行(windows dos shell)调用它是有效的 noverify.exe -exclude-checks arraySyntax,phpdocLint               -output result.txt               C:\Dev\PHP\ResourceSpace_9_0_13357\include问题是我无法将参数传递给cmnd := exec.Command("noverify.exe", args)options := " -exclude-checks arraySyntax, PHPDoc"pathToCode := "C:\\Dev\\PHP\\ResourceSpace_9_0_13357\\include"// this workscmnd := exec.Command("noverify.exe", pathToCode)args := []string{options, pathToCode}arg := strings.Join(args, "")// passing options does not work// cmnd := exec.Command("noverify.exe", arg)    b, err := cmnd.CombinedOutput()我尝试过什么你可以在这个要点中找到我的源代码似乎 args 作为一个字符串连接起来,,尽管上面的分隔符是空的。问题如何传递多个参数exec.Comman("yourFoo.exe", cmdArgs...)为什么我的尝试在 Windows 上不起作用?
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

有多种选项可将参数传递给 exec.Command:

您可以使用多个字符串作为参数:

cmd := exec.Command("your-command", "arg1", "arg2")

如果您有参数切片,则可以使用扩展运算符

args := []string{"-exclude-checks", "arraySyntax,phpdocLint", "-output", "result.txt", "your-path"}
cmd := exec.Command("your-command", args...)

问题二:在你的代码中

options := " -exclude-checks arraySyntax, PHPDoc"
pathToCode := "C:\\Dev\\PHP\\ResourceSpace_9_0_13357\\include"
    args := []string{options, pathToCode}

您将两个选项传递给外部程序。如果你在命令行上写了同样的内容,你就通过了

your-command.exe " -exclude-checks arraySyntax, PHPDoc" "your-path"

这是行不通的,也是你的程序行不通的原因。

简而言之,无论在命令中的任何位置放置空格,都需要有一个单独的参数exec.Command

查看完整回答
反对 回复 2023-07-17
  • 1 回答
  • 0 关注
  • 72 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信