debugging - 如何在带有Golang的VSCode中以 Debug模式传递命令行参数

标签 debugging go command-line visual-studio-code arguments

我在使用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/

相关文章:

c++ - 对于这种奇怪的崩溃有什么可能的解释吗?

debugging - 如何确定代码是作为函数执行还是使用单元格模式执行

go - 防止为所有不匹配的请求调用 http.handleFunc ("/", func(w, r) { }) 处理程序

unit-testing - 子目录的 golang 测试失败

linux - 使用du -sh *命令时如何根据子目录的大小排序?

php - 为什么我的 Netbeans Xdebug session 在一段时间不活动后超时

python - 模块 'xlwings' 没有属性 'Book'

go - http.FileServer 正在发送 "404 page not found"

linux - 在命令行上将字符串转换为十六进制

variables - 如何将子字符串命令应用于 XP cmd 脚本中的双百分比变量?