首页 > 解决方案 > 如何使用 VSCode 和管道命令进行调试

问题描述

我正在使用 VScode,我想调试一个与管道命令一起使用的程序。

在控制台中,我运行我的程序

cat dataset.txt | python my_program.py

如何配置 VSCode 以传递cat命令,以便正确调试程序?

我怀疑我需要编辑launch.json

{
    "name": "Python: Current File (Integrated Terminal)",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal"
},

标签: pythondebuggingvisual-studio-code

解决方案


如果将“console”更改为“externalTerminal”,则在运行程序时将打开一个外部终端窗口。此窗口已将标准输入连接到键盘,因此如果您键入或粘贴内容,它将被传递给程序,直到您发送或键入 ctrl-z。标准输出转到窗口。调试和断点按预期工作。


推荐阅读