56

I've been using VS Code for quite some time and just today I started having this strange issue. Previously if I started debugging an program (F5) it would start debugging and show output in the "Debug Console":

enter image description here

But now It starts debugger in the "Terminal" enter image description here and also outputs to "Debug Console".

Here is my launch.json:

{
    "version": "0.2.0",
    "configurations": [{
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}"
        }
    ]
}


I want output only in the "Debug Console" (previously default behavior). Please help me with setting it back to the way it was.

informatik01
  • 16,038
  • 10
  • 74
  • 104
HaMAD
  • 787
  • 2
  • 6
  • 11

8 Answers8

65

Edit 3

As with the release 2019.4.0 of the python extension it is now possible to set the console option to internalConsole (#4321).

In .vscode/launch.json:

"console": "internalConsole"

Edit 2

As suggested in omartin2010's answer you can additionally set the option

"internalConsoleOptions": "openOnSessionStart"

to automatically open the debug console when starting debugging.

Edit 1

Setting the "console" option explicitly to "none" was originally the way to go (see answers), but now "none" is no longer valid (see Edit 3 above)

"console": "none"

Original answer

To ensure that the output is written to the debug console you can set the debugOptions. Adding the following entry to your configuration in yourlaunch.json should fix it:

"debugOptions": [
    "RedirectOutput"
]
LightCC
  • 9,804
  • 5
  • 52
  • 92
HaaLeo
  • 10,065
  • 3
  • 44
  • 55
  • 1
    It already does that. But it prints to both terminals and also when i start debugging it goes to the terminal instead of the debug console – HaMAD Mar 30 '18 at 10:55
  • 3
    Then maybe setting the [console](https://code.visualstudio.com/docs/python/debugging#_console) option explicitly helps. Try to set `"console": "integratedTerminal"`: – HaaLeo Mar 30 '18 at 11:01
  • If you end up needing the terminal it will be more problematic. It would be easier to add a new configuration instead with none – SnitchingAuggie Jun 10 '18 at 19:13
  • `internalConsoleOptions` worked for me when no terminal was showing when debug starts – natenho Nov 20 '22 at 19:16
12

It's also possible, as of I guess not too long ago, to add this option... not sure it was possible before:

{
...
            "internalConsoleOptions": "openOnSessionStart",
...
}

hope this helps

Ali
  • 2,702
  • 3
  • 32
  • 54
omartin2010
  • 421
  • 1
  • 5
  • 15
11

I had the same problem but I solved it by adding a new configuration at the top that looked like this:

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "internalConsole"
},

I found this a better solution because I didn't have to change one of my other debug functions. In your case the "Python: Terminal (integrated)" debug option. Which I need as much as I need the debug console function. I use both function and they show the output where I want the output to be shown.

Nejc Galof
  • 2,538
  • 3
  • 31
  • 70
SnitchingAuggie
  • 494
  • 3
  • 14
  • 3
    Now I get the output only in the debug console as desired, however, how do I get the debug console to automatically launch when i start debugging? – Zubda Jul 11 '18 at 22:07
11

Originally the config below worked, but it seems to have been deprecated and it now throws an error:

    "console": "none" 

The new usage is:

    "console": "internalConsole"

There's a bug logged in GitHub to update the docs here.

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
Tammy Treit
  • 111
  • 1
  • 4
5
{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "stopOnEntry": false,
    "console": "none"
},

these are my launch.json settings and it's working with this.

Pang
  • 9,564
  • 146
  • 81
  • 122
anils
  • 51
  • 1
  • 3
  • 1
    Basically, the same answer as @SnitchingAuggie except the "stopOnEntry" attribute. Please explain why this is significant. – Barns Nov 14 '18 at 17:57
2

The accepted answer didn't work for me as it doesn't appear to be an option on my version of VSCode Version 1.30.2 (1.30.2):

Unknown console type 'none'.

The solution for me was to use the internalConsole option instead. I suppose it must be defaulting to the integratedTerminal option on my version.

Here is an example:

NOTE: this is an example from my nodejs project but the console portion is still relevant regardless of project type. I have included more to show some context as well as other features such as envFile usage.

...    
{
    "type": "node",
    "request": "launch",
    "name": "Launch Program",
    "envFile": "${workspaceRoot}/.env",
    "program": "${workspaceFolder}/src/index.js",
    "autoAttachChildProcesses": true,
    "console": "internalConsole"
},
...
Matthew Sanders
  • 4,875
  • 26
  • 45
  • OP's question refers to _python_ debugging not _nodejs_ – HaaLeo Jan 30 '19 at 08:52
  • 2
    The project type is actually pretty irrelevant in this case. This is an issue with the IDE setup in general and applicable to any project type printing output to the debug console. I understand it may be confusing if you copy and paste my full configuration so I will update my answer. – Matthew Sanders Jan 30 '19 at 16:36
1

Use the recommended config as per the VScode docs

But also append "internalConsoleOptions": "openOnSessionStart"

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Debug Tests",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "purpose": [
                "debug-test" // this value is mandatory for it to launch the debug console
            ],
            "console": "integratedTerminal",
            "justMyCode": false,
            "internalConsoleOptions": "openOnSessionStart"
        }
    ]
}
Mark
  • 1,337
  • 23
  • 34
-1

If you're like me and you actually wanted to do the opposite (i.e. stop VSCode from automatically switching to the "Debug Console" Tab instead of just staying on the "Terminal Tab") then I found that the solution was to add this setting to your launch.json file:

"avoidWindowsConsoleRedirection": true
Nathaniel Ruiz
  • 484
  • 6
  • 12