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
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()
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.
exec.Comman("yourFoo.exe", cmdArgs...)
There are multiple options to pass arguments to exec.Command:
You can use multiple 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...)
To question two: In your code
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.
In short, wherever you put a space between in a command, you need to have a separate argument to exec.Command
. The example also does this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.