Getting random command-line args when compiling and debugging in Visual Studio Code

Viewed 330

So I'm making an example program to learn how to build and debug C projects in Visual Studio Code. For reference, here's my launch.json and tasks.json for the project:

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
        }
    }
]

And here's 'test.c':

test.c

#include <stdio.h>

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


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

This is what I see for my command-line arguments even though I gave no command-line arguments:

enter image description here

There turns out to be 3 extra command-line arguments "2>CON", "1>CON", and "<CON" as you can see in the watch panel. Why is this happening even though I gave 0 command-line arguments?

1 Answers

After some searching and testing in Visual Studio Code, I discovered an option called "externalConsole" within launch.json that redirects output to an actual command prompt window, removing the additional re-directions from the command-line. There's also another option called "avoidWindowsConsoleRedirection" that avoids adding the extra command-line arguments/re-directions without an external command-prompt displaying. If both options are present within your launch.json file, "externalConsole" takes precedence. Example of using both below:

"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"

    }
]
Related