我在使用golang在VSCode( Debug模式)中传递命令行参数时遇到困难。
以下是小代码示例和launch.json:
package main
import (
"flag"
"fmt"
)
func main() {
flag1Ptr := flag.Bool("flag1", false, "flag1 is a flag")
flag.Parse()
fmt.Println(*flag1Ptr)
fmt.Println("Hello, world")
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": [
"-flag1"
]
}
]
}
The output is always "false" for *flag1Ptr but it should be "true".
Update: The issue disappeared after closing down VSCode and reopening it (I am on a Mac(osX))
最佳答案
列出所有参数,例如,
命令是:
"hello.exe -in InfoEntity.java -out aa.out"
调试配置为:{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": ["-in", "InfoEntity.java", "-out", "aa.out"]
}
]
}
关于debugging - 如何在带有Golang的VSCode中以 Debug模式传递命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59142164/