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

}

Gama11
  • 31,714
  • 9
  • 78
  • 100
echo
  • 767
  • 2
  • 9
  • 24
  • "./a.out 1 – echo Sep 17 '17 at 00: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 '17 at 00: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 .https://stackoverflow.com/questions/32863807/visual-studio-code-redirect-input-on-debug – echo Oct 31 '17 at 22:40

2 Answers2

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.

C. Peck
  • 3,641
  • 3
  • 19
  • 36
  • 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 '21 at 05:36
  • @Dalton where are you able to see output, does it works if externalConsole is true – beta_me me_beta May 03 '21 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` – Kuznetsov-M Jul 28 '22 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'"

The Bic Pen
  • 773
  • 6
  • 21