Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
800 views
in Technique[技术] by (71.8m points)

visual studio code - Reading input during debugging in Python with VSCode

Here is the extension for python I used in the vs code: python extension.

When I use the debugging feature provided by the extension, it will hang in there and do nothing if it needs input from the command line.

Where can I input values to step over the input statement in the vs code?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The trick to getting this to work is on the extension's(Don Jayamanne's Python) wiki page. You have to include "externalConsole": true setting in your launch.json file's "name": "Python" section.

The extension's wiki confirms that this does not work by default:

This allows for capturing of input from the console/terminal window applications, which isn't possible in the standard VSCode debugger.

Here are the steps to getting this to work:

  1. From the Debug window (Ctrl+Shift+D), press the little gear icon to open (or to generate) a launch.json file. It gets placed into a .vscode directory in what ever folder you have selected as your "Open Folder" in VS Code.
  2. You have to add pythonPath parameter to the first configuration block. This is needed to have the debugger work at all.
  3. You also have to add and externalConsole parameter to the same block. This is what is needed to have the debugger accept input. When you debug, a separate window will open outside of VS Code but works well otherwise.
  4. After you add both settings, the block should look something like this. I did not have to change anything else in the rest of the launch.json file.

    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "program": "${file}",
        "pythonPath": "C:/Users/igor/Documents/Tools/WinPython-32bit-3.4.3.7Slim/python-3.4.3/python.exe",
        "externalConsole": true,
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...