13

I am trying to follow the direction from this post

Visual Studio Code redirect input on debug

but when I add the console config to the launch.json file

"console": "integratedTerminal"

it throws a "Property console is not allowed". and when I debug the program it still waits on input and never reach break point like I would if I start in shell like

"./a.out 1 test1.txt"

"./a.out 1 <test1.txt"    

Full config

{
    "version": "0.2.0",
    "configurations": [

    {
        "name": "(lldb) Launch",
        "type": "cppdbg",
        "request": "launch",
        //"program": "${workspaceRoot}/a.out.dSYM/Contents/Resources/DWARF/a.out",
        "program": "${workspaceRoot}/a.out",
        "args": ["1", "<","test1.txt"],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}/",
        "environment": [],
        "externalConsole": true,
        "MIMode": "lldb",
        //"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "console": "integratedTerminal"
        //"preLaunchTask": //"build test1"
    }
]

}

3
  • "./a.out 1 <test1.txt" . should be, it gets cut of somehow when I post it in the main article
    – echo
    Sep 17, 2017 at 0:50
  • Also if someone could show me how to start the cpp program in shell and then attach my lldb debug to it in vscode. That will also work thanks
    – echo
    Sep 17, 2017 at 0:52
  • After month of research it seems like currently there is no way to do so in Cpp for LLDB debugger. But there is a workaround for Node, as listed in the question .stackoverflow.com/questions/32863807/…
    – echo
    Oct 31, 2017 at 22:40

2 Answers 2

9

I use GDB instead of lldb but still encountered the same issue. It waited for an input when I typed arguments in the "launch.json" file this way:

"args": ["<", "test1.txt"],

But it started working properly when I had rewritten it in the following manner:

"args": ["<", "${workspaceFolder}/test1.txt"],

I think that one should add a parent folder even though the input file is in the workspace folder or simply use the full path.

3
  • you saved my sanity! first time debugging in vscode.. that compatibility with gdb in linux and sending file to standard input.. omg ... i was trying also some recommendation like have external file where you put "r < /path/to/file.txt" and just put it as args to gdb, but it also didn't work (for me) in vscode launch.json... Finally, thank you!!! :D
    – Dalton
    Mar 17, 2021 at 5:36
  • @Dalton where are you able to see output, does it works if externalConsole is true May 3, 2021 at 17:52
  • "args": ["<", "${workspaceFolder}/test1.txt"] and externalConsole: true not working for mac vscode. Console output: zsh: no such file or directory: /correct/path/to/my/file/input.txt Jul 28, 2022 at 13:05
2

If you use the integrated console, the < doesn't get interpreted by a shell. Usually, using externalConsole: true fixes the problem since this uses a shell. But if the external console doesn't work on your system for whatever reason and you're forced to use externalConsole: false, the workaround is to let GDB create the shell: miDebuggerArgs: "'-ex' 'run < /path/to/test1.txt'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.