[英]Go use of exec.Command on windows for noverify
我想使用 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 works
cmnd := 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()
你可以在这个 gist 中找到我的源代码尽管上面的分隔符是空的,
但 args 似乎被连接为一个由 分隔的字符串。
exec.Comman("yourFoo.exe", cmdArgs...)
有多个选项可以将参数传递给 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
提供一个单独的参数。 该示例也执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.