14

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 Commented 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 Commented 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/… Commented Oct 31, 2017 at 22:40

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 where are you able to see output, does it works if externalConsole is true
"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
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'"

4 Comments

works just fine for me in integrated console/terminal. what OS are you on?
IIRC this was on Ubuntu 20.04. This was a while ago though, so I don't remember the exact steps to reproduce this.
so you can no longer reproduce the behaviour you previously observed with your new setup? if so, what is the behaviour that you now observe?
I don't remember where I encountered this issue. None of my current configs have that string at this point. Sorry.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.