首页 > 解决方案 > VsCode 在运行模式和调试模式之间的不同行为

问题描述

当我在运行模式下运行以下 python 代码时,响应等于 0,当我在调试模式下运行它时,响应为 127 并且/bin/sh: ping: command not found发生故障。

cmd = '-c 1'
host = 192.168.1.1
response = subprocess.call(f'ping {cmd} {host}, shell=True')

我的 launch.json 看起来像这样:

{
    // 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: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

使用时response = os.system(f'ping {cmd} {host}'),运行模式下响应为0,调试模式下响应为32512,出现故障sh: ping: command not found

有人能帮我吗?

标签: pythonvisual-studio-codeping

解决方案


推荐阅读