简体   繁体   English

VS Code 在集成终端而不是调试控制台中开始调试

[英]VS Code starts debugging in integrated terminal instead of debug console

I've been using VS Code for quite some time and just today I started having this strange issue.我使用 VS Code 已经有一段时间了,直到今天我才开始遇到这个奇怪的问题。 Previously if I started debugging an program (F5) it would start debugging and show output in the "Debug Console":以前,如果我开始调试程序 (F5),它会开始调试并在“调试控制台”中显示 output:

在此处输入图像描述

But now It starts debugger in the "Terminal"但是现在它在“终端”中启动调试器在此处输入图像描述 and also outputs to "Debug Console".并且还输出到“调试控制台”。

Here is my launch.json :这是我的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).只想在“调试控制台”中使用 output(以前是默认行为)。 Please help me with setting it back to the way it was.请帮我把它设置回原来的样子。

Edit 3编辑 3

As with the release 2019.4.0 of the python extension it is now possible to set the console option to internalConsole ( #4321 ).与 python 扩展的2019.4.0 版本一样,现在可以将console选项设置为internalConsole ( #4321 )。

In .vscode/launch.json :.vscode/launch.json

"console": "internalConsole"

Edit 2编辑 2

As suggested in omartin2010's answer you can additionally set the option正如omartin2010 的回答中所建议的,您可以另外设置选项

"internalConsoleOptions": "openOnSessionStart"

to automatically open the debug console when starting debugging.开始调试时自动打开调试控制台。

Edit 1编辑 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)“控制台”选项显式设置为"none"最初是要走的路(请参阅答案),但现在“无”不再有效(请参阅上面的编辑 3)

"console": "none"

Original answer原答案

To ensure that the output is written to the debug console you can set the debugOptions .为确保将输出写入调试控制台,您可以设置debugOptions Adding the following entry to your configuration in your launch.json should fix it:将以下条目添加到launch.json的配置应该可以修复它:

"debugOptions": [
    "RedirectOutput"
]

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 .在 GitHub 中记录了一个错误以更新文档here

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.在您的情况下,“Python:终端(集成)”调试选项。 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.我使用这两个函数,它们在我想要显示输出的地方显示输出。

{
    "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.这些是我的 launch.json 设置,它正在处理这个。

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希望这有帮助

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) :接受的答案对我不起作用,因为它似乎不是我的 VSCode Version 1.30.2 (1.30.2)版本中的一个选项:

Unknown console type 'none'.

The solution for me was to use the internalConsole option instead.我的解决方案是改用internalConsole选项。 I suppose it must be defaulting to the integratedTerminal option on my version.我想它必须默认为我的版本上的integratedTerminal选项。

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"
},
...

Use the recommended config as per the VScode docs根据VScode 文档使用推荐的配置

But also append "internalConsoleOptions": "openOnSessionStart"还有 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"
        }
    ]
}

All the output options所有输出选项<\/h2>

In newer versions of VS Code, here are your options for the "console"<\/strong> property in .vscode\/launch.json<\/code> .在较新版本的 VS Code 中,您可以选择.vscode\/launch.json<\/code>中的“控制台”<\/strong>属性。 With a single config, this will change the output and input target for both run and debug launches.使用单个配置,这将更改运行和调试启动的输出和输入目标。

如果您像我一样并且实际上想要做相反的事情(即阻止 VSCode 自动切换到“调试控制台”选项卡,而不是仅仅停留在“终端选项卡”上),那么我发现解决方案是添加此设置到您的launch.json<\/code>文件:

"avoidWindowsConsoleRedirection": true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM