在 windows 上使用 exec.Command 进行 noverify
时间:2023-04-16
浏览:352
作者:佚名
欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《在 windows 上使用 exec.Command 进行 noverify》,这篇文章主要讲到golang等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!
问题内容
我想使用 VKCOM/ novify来分析代码。使用此命令从命令行(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...) - 为什么我的尝试在 Windows 上不起作用?
正确答案
有多个选项可以将参数传递给 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.
该示例也执行此操作。
以上就是《在 windows 上使用 exec.Command 进行 noverify》的详细内容,更多关于golang的资料请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
12.01
12.01
热门专题
