[英]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.请帮我把它设置回原来的样子。
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"
As suggested in omartin2010's answer you can additionally set the option正如omartin2010 的回答中所建议的,您可以另外设置选项
"internalConsoleOptions": "openOnSessionStart"
to automatically open the debug console when starting debugging.开始调试时自动打开调试控制台。
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"
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"
]
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"
}
]
}
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.使用单个配置,这将更改运行和调试启动的输出和输入目标。
externalTerminal<\/code> - launches script in a new default terminal in a new window (outside VS Code)
externalTerminal<\/code> - 在新窗口中的新默认终端中启动脚本(在 VS Code 之外)
<\/li>
integratedTerminal<\/code> - launches in a new terminal in the VS Code "terminal" window.
integratedTerminal<\/code> - 在 VS Code“终端”窗口的新终端中启动。
It renames this terminal to "Python" and reuses it in the future if you run again.如果您再次运行,它将将此终端重命名为“Python”并在将来重用它。<\/li>
internalConsole<\/code> - sends output to the "Debug Console".
internalConsole<\/code> - 将输出发送到“调试控制台”。
With this method I do not believe there is any way to input user responses to stdin (ie when responding to an input<\/code> command with the keyboard, etc.)
使用这种方法,我不相信有任何方法可以输入用户对标准输入的响应(即,当使用键盘响应input<\/code>命令时等)
<\/li><\/ul>
Note 1: Creating launch configurations注 1:创建启动配置<\/h3>You can create a new launch.json<\/code> file from the "RUN AND DEBUG" tab on the far left icon strip.
您可以从最左侧图标条上的“运行和调试”选项卡创建一个新的launch.json<\/code>文件。
You must do this at least once setup a default config for the current folder or workspace.<\/strong>您必须至少为当前文件夹或工作区设置默认配置一次。<\/strong>
Note 2: Multiple configs注2:多个配置<\/h3>It is possible to create multiple configurations in your launch.json<\/code> file for different purposes.
可以在您的launch.json<\/code>文件中为不同目的创建多个配置。
For example, one for normal run commands, and one for debugging.例如,一个用于正常运行命令,一个用于调试。 This would allow you to output to different terminal types when running tests or normal launches vs. debugging.这将允许您在运行测试或正常启动与调试时输出到不同的终端类型。
{ \/\/ 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": "Py: Current File", "type": "python", "request": "launch", "program": "${file}", "cwd": "${workspaceRoot}", "console": "integratedTerminal", "env": { "_PYTEST_RAISE": "1" }, "debugOptions": [ "RedirectOutput" ] }, { "name": "PyTest: Debug", "type": "python", "request": "launch", "purpose": ["debug-test"], "program": "${file}", "cwd": "${workspaceRoot}", "console": "internalConsole", "justMyCode": true, "args": ["--no-cov"], "env": { "_PYTEST_RAISE": "1" }, "debugOptions": [ \/\/ "WaitOnAbnormalExit", \/\/ "WaitOnNormalExit", "RedirectOutput" ] }, ] }<\/code><\/pre>"
如果您像我一样并且实际上想要做相反的事情(即阻止 VSCode 自动切换到“调试控制台”选项卡,而不是仅仅停留在“终端选项卡”上),那么我发现解决方案是添加此设置到您的launch.json<\/code>文件:
"avoidWindowsConsoleRedirection": true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.