简体   繁体   English

VS Code将launch.json转化为实际命令

[英]VS Code launch.json into an actual command

I want to make a Python script that transforms a part of VS Code launch.json into a normal command for a terminal.我想制作一个 Python 脚本,将 VS Code launch.json的一部分转换为终端的正常命令。 I need it to communicate with non-VSCode users.我需要它来与非 VSCode 用户交流。 Here is the example:这是示例:

import json

launch_json = '''
        {
            "name": "temp",
            "type": "python",
            "request": "launch",
            "program": "script.py",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": ["abcd",
                     "--log", "log.txt"],
            "env": {"CUDA_VISIBLE_DEVICES":"0"},
        }
'''

d = json.loads(launch_json)
command = d["program"] + " " + " ".join(d["args"])
print(command)

If I run it, I have the following error:如果我运行它,我会遇到以下错误:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 12 column 9 (char 344)

How do I make the script?如何制作脚本?

There is an extra comma at the end of launch_json launch_json末尾多了一个逗号

{
   "env": {"CUDA_VISIBLE_DEVICES":"0"}, <- should not be here
}

so just replace it with所以只需将其替换为

{
   "name": "temp",
   "type": "python",
   "request": "launch",
   "program": "script.py",
   "console": "integratedTerminal",
   "justMyCode": false,
   "args": ["abcd",
            "--log", "log.txt"],
   "env": {"CUDA_VISIBLE_DEVICES":"0"}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VS Code:如何在launch.json中通过shell命令获取进程ID? - VS Code: how to get process ID via shell command in launch.json? 如何通过 launch.json 在 VS 代码中将参数传递给 python 解释器(而不是 python 代码) - How to pass an argument to the python interpreter (not to the python code) in VS code via launch.json 在 VS Code 中,我根本无法在 launch.json 中运行命令行 arguments。 我究竟做错了什么? - In VS Code I just can't get command line arguments in launch.json working at all. What am I doing wrong? 有人可以在Mac OS X launch.json上的VS Code中查看这些错误吗? - Can someone look at these bugs in VS Code on mac OS X launch.json isn't working 在 VS Code 上运行 Flask 应用程序时无法识别 launch.json 中的环境变量 - Environment variables in launch.json not recognized when running Flask application on VS Code 如何在 VS 代码中配置 launch.json 以在 Windows 中接受网络路径(python) - how to configure the launch.json in VS code to accept a network path (python) in windows 在 VS Code 中,当通过调试器运行 python 程序时,在 launch.json 中设置了 internalConsole,然后我无法从命令行接收输入 - In VS Code, when running a python program via the debugger, with internalConsole set in launch.json, then I can't receive input from the command line 无法让 VS Code 从 launch.json 传递 arguments 到 Python - Cannot get VS Code to pass arguments to Python from launch.json 在 launch.json 中从 BEGINNING 附加启动命令 - Append launch command from the BEGINNING in launch.json 修改launch.json - Modify launch.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM