在Windows上使用exec.Command进行Noverify [英] Go use of exec.Command on windows for noverify

查看:76
本文介绍了在Windows上使用exec.Command进行Noverify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用VKCOM/ noverify 来分析代码.使用此命令从命令行(Windows dos shell)调用它可以正常工作

I want to use VKCOM/noverify to analyse code. Calling it from the command-line (windows dos shell) using this command works

 noverify.exe -exclude-checks arraySyntax,phpdocLint 
              -output result.txt 
              C:\Dev\PHP\ResourceSpace_9_0_13357\include

麻烦的是我无法将参数传递给cmnd := exec.Command("noverify.exe", args)

The trouble is that i am unable to pass arguments to 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()

我尝试了什么

您可以在此要旨中找到我的源代码尽管分隔符在上方为空,但字符串仍由,分隔.

What have i tried

You can find my source code in this gist It seems that args are joined as a string seperated by , despite that the separator is empty above.

  1. 如何将多个参数传递给exec.Comman("yourFoo.exe", cmdArgs...)
  2. 为什么我的尝试在Windows上不起作用?

推荐答案

有多种方法可以将参数传递给exec.Command:

There are multible options to pass arguments to exec.Command:

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

You can use multible strings as arguments:

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

如果有一部分参数,则可以使用传播运算符

If you have a slice of arguments, you can use the spread operator

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}

您要将两个选项传递给外部程序. 如果您在命令行上写了相同的代码,则可以通过

you're passing two options to the external program. If you wrote the same on the command line, you pass

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

这不起作用,也是您的程序不起作用的原因.

This doesn't work, and is also the reason your program doesn't work.

简而言之,无论在命令中的任何位置之间放置空格,都需要为exec.Command提供单独的参数. 示例也可以做到这一点.

In short, whereever you put a space between in a command, you need to have a separate argument to exec.Command. The example also does this.

这篇关于在Windows上使用exec.Command进行Noverify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆