在Visual Studio代码中进行编译和调试时获取随机命令行参数

问题描述 投票:0回答:1

因此,我正在编写一个示例程序来学习如何在Visual Studio Code中构建和调试C项目。作为参考,这是我的项目的launch.jsontasks.json

launch.json:

"version": "0.2.0",
"configurations": [
    {
        "name": "test-project",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}\\test.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "build test-project"
    }
]

tasks.json:

"version": "2.0.0",
"tasks": [
    {
        "label": "build test-project",
        "type": "shell",
        "command": "gcc",
        "args": [
            "-std=c99",
            "-g",
            "${workspaceFolder}\\test.c",
            "-o",
            "${workspaceRoot}\\test.exe"              
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

这里是'test.c':

test.c

#include <stdio.h>

int main(int argc, char* argv[]){


    int t = 9;
    int p = 10;
    return 0;
}

即使我未提供任何命令行参数,这也是我看到的命令行参数:

enter image description here

事实证明,您可以在监视面板中看到3个额外的命令行参数"2>CON""1>CON""<CON"。即使我给了0个命令行参数,为什么会发生这种情况?

c visual-studio gcc
1个回答
0
投票

[在Visual Studio Code中进行了一些搜索和测试之后,我在"externalConsole"中发现了一个名为launch.json的选项,该选项将输出重定向到实际的命令提示符窗口,从而从命令行中删除了其他重定向。还有一个称为"avoidWindowsConsoleRedirection"的选项,可以避免在不显示外部命令提示符的情况下添加额外的命令行参数/重定向。如果launch.json文件中同时存在两个选项,则"externalConsole"优先。下面同时使用的示例:

"version": "0.2.0",
"configurations": [
    {
        "name": "test-project",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}\\test.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "avoidWindowsConsoleRedirection": true,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "build test-project"

    }
]
推荐问答
热门问答
最新问答