duanchuang3182 2019-09-02 23:37
浏览 329

在Windows上使用exec.Command进行Noverify

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()

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.

Questions

  1. How to pass multiple arguments to exec.Comman("yourFoo.exe", cmdArgs...)
  2. Why is my attempt not working on windows?
  • 写回答

1条回答 默认 最新

  • duanfu9523 2019-09-03 07:14
    关注

    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...)
    

    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, whereever you put a space between in a command, you need to have a separate argument to exec.Command. The example also does this.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料