如何使用vscode launch.json中运行which命令的输出



我想使用运行which brownie的输出作为launch.json"program"的值。例如,在launch.json的这个片段中

"configurations": [
{
"name": "Brownie: run deploy.js",
"type": "python",
"request": "launch",
"program": "/home/fanta/.local/virtualenv/python3.10/bin/brownie",
"console": "integratedTerminal",
"args": ["run", "scripts/deploy.js"]
},

我想用which brownie的输出替换我硬连接的/home/fanta/.local/virtualenv/python3.10/bin/brownie的完整路径。我该怎么做?

您可以设置一个执行which brownie并将其写入临时文件的preLaunchTask

{
"version": "2.0.0",
"tasks": [
{
"label": "which brownie",
"type": "shell",
"command": "which brownie > /tmp/brownie-loc.txt"
}
]
}

使用扩展命令变量,您可以使用命令extension.commandvariable.file.content来使用启动中的文件内容

{
"version": "0.2.0",
"configurations": [
{
"name": "Brownie: run deploy.js",
"type": "python",
"request": "launch",
"program": "${input:browniePath}",
"console": "integratedTerminal",
"args": ["run", "scripts/deploy.js"],
"preLaunchTask": "which brownie"
}
],
"inputs": [
{
"id": "browniePath",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "/tmp/brownie-loc.txt"
}
}
]
}

最新更新