David Jentjens
David Jentjens

Reputation: 646

How to read console input from VScode while live-debugging

I'm trying to live-debug a C program which, using the C/C++ expansion from VScode, also allows me to write direct input to the console using scanf(). However, when I debug the code it opens the debug console, which does not allow me to enter any input.

I found two threads in which people answered this problem:

https://github.com/OmniSharp/omnisharp-vscode/issues/1053

Debug Console window cannot accept Console.ReadLine() input during debugging

Both advise to set the "console" property in the launch.json file to either "externalTerminal" or "integratedTerminal". I however couldn't find the property or create it for that matter, because it doesn't exist in my file.

I do have the "externalConsole" property, which can be set to either true or false. But both options seem to open the debug console like before.

The launch.json file:

 {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/mnt/c/Users/David/Documents/code/puc-rio/inf1010/lab8/teste.out",
            "args": [],
            "stopAtEntry": true,
            "cwd": "/mnt/c/Users/David/Documents/code/puc-rio/inf1010/lab8/",
            "environment": [],
            "externalConsole": true,
            "windows": {
                "MIMode": "gdb",
                "miDebuggerPath": "/usr/bin/gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            },
            "pipeTransport": {
                "pipeCwd": "",
                "pipeProgram": "c:\\windows\\sysnative\\bash.exe",
                "pipeArgs": [
                    "-c"
                ],
                "debuggerPath": "/usr/bin/gdb"
            },
            "sourceFileMap": {
                "/mnt/c": "${env:systemdrive}/",
                "/usr": "C:\\Users\\David\\AppData\\Local\\Packages\\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr"
            }
        }
    ]

What happens when I try to write something to the debug console:

Unable to perform this action because the process is running.

Upvotes: 5

Views: 5433

Answers (1)

Andy Wu
Andy Wu

Reputation: 51

I had the same confusion before I saw your post. In my Windows environment, I set "externalConsole" to be true. After that, when the debugging started there will be a cmd shell of my program (not the "debug console" provided by VScode), in which stdin can be typed.!(https://i.sstatic.net/KKlJP.jpg)

Upvotes: 4

Related Questions