VSCode: running the exact same terminal command produces different results depending on if it was run by clicking a UI button

huangapple go评论52阅读模式
英文:

VSCode: running the exact same terminal command produces different results depending on if it was run by clicking a UI button

问题

问题

考虑以下终端命令:

PS C:\dev> c:; cd 'c:\dev'; & C:\Users\{user}\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\{user}\.vscode\extensions\ms-python.python 2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '60106' '--' 'c:\dev\open.py'

当我在VSCode UI(右上角)点击“Debug Python File”按钮时,会生成并运行此行。通过这种方法,调试器可以正常运行文件。如果我手动在终端中运行完全相同的命令行,则会收到以下错误:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
如果需要,可以提供更多详细信息

问题

我不理解的是什么导致了这个问题?VSCode一定是在运行此命令行之外执行了其他操作,是什么操作?我正在努力想出正确的搜索查询,以找到我需要理解的内容。

环境

我正在使用安装了Python扩展程序包的VSCode。尽可能标准的环境。

目的

我正在尝试弄清楚从VSCode运行我的脚本的最快/最简单的方法,使用调试器,并指定命令行参数,而不是在启动配置中指定参数。

英文:

problem

Consider the following terminal command:

PS C:\dev> c:; cd 'c:\dev'; & C:\Users\{user}\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\{user}\.vscode\extensions\ms-python.python 2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '60106' '--' 'c:\dev\open.py'

This line is generated and run when I click the "Debug Python File" button in the VSCode UI (top-right). Through this method, the debugger runs the file just fine. If I instead manually run the exact same line in the terminal, I get the following error:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
There are more details, can include if necessary

question

What do I not understand that's tripping this up? VSCode must be doing something in addition to running this command line, what is it? I'm struggling to come up with the correct search query to find what I need to understand here.

environment

I'm using VSCode with the Python extensions package installed. As standard an environment as I could get.

purpose

I'm trying to figure out the quickest/easiest way to run my script, from VSCode, with the debugger, with command line arguments, rather than specifying args in the launch config.

答案1

得分: 1

以下是您要翻译的内容:

答案是肯定的,使用UI按钮进行调试将加载launch.json中的配置,其命令由扩展生成,存在复杂性,因此不能直接简单复制。您可以观察到使用UI按钮调试的每个命令中端口都会更改。

如果要使用命令行进行调试,请遵循以下语法:

    --listen | --connect
    [<host>:]<port>
    [--wait-for-client]
    [--configure-<name> <value>]...
    [--log-to <path>] [--log-to-stderr]
    <filename> | -m <module> | -c <code> | --pid <pid>
    [<arg>]...

简单示例:

VSCode: running the exact same terminal command produces different results depending on if it was run by clicking a UI button

有关VSCode调试的更多信息:

https://code.visualstudio.com/docs/editor/debugging

https://code.visualstudio.com/docs/python/debugging

https://code.visualstudio.com/docs/python/python-tutorial#_configure-and-run-the-debugger

英文:

The answer is yes, the debugging using the UI button will load the configuration in launch.json, and its commands are generated by the extension, there is complexity, so direct and simple copying cannot be used. You can observe that the port changes in every command that uses the UI button to debug.

If you want to use the command line for debugging, follow the syntax:

python -m debugpy
    --listen | --connect
    [&lt;host&gt;:]&lt;port&gt;
    [--wait-for-client]
    [--configure-&lt;name&gt; &lt;value&gt;]...
    [--log-to &lt;path&gt;] [--log-to-stderr]
    &lt;filename&gt; | -m &lt;module&gt; | -c &lt;code&gt; | --pid &lt;pid&gt;
    [&lt;arg&gt;]...

Simple example:

VSCode: running the exact same terminal command produces different results depending on if it was run by clicking a UI button

More information about vscode debugging:

https://code.visualstudio.com/docs/editor/debugging

https://code.visualstudio.com/docs/python/debugging

https://code.visualstudio.com/docs/python/python-tutorial#_configure-and-run-the-debugger

huangapple
  • 本文由 发表于 2023年5月11日 00:13:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定