[英]VS Code: how to get process ID via shell command in launch.json?
In our Visual Studio Code configuraiton launch.json looks like this:在我们的 Visual Studio Code 配置中,launch.json 看起来像这样:
{
"version": "0.2.0",
"configurations": [
{
"type": "fb-python",
"request": "attach",
"name": "Attach to a running Python process",
"processId": "${command:pickProcess}",
"subProcess": true,
"justMyCode": true,
"redirectOutput": true,
"django": true,
"client": "instagram"
}
]
}
It shows process selection dialog every time I click "Debug".每次单击“调试”时,它都会显示进程选择对话框。 What I want to do is to calculate the process ID using a shell command:
我想做的是使用 shell 命令计算进程 ID:
ps -ef | grep "async uWSGI worker 1" | grep -v grep | awk '{print $2}'
How can I do that without writing a custom extension?在不编写自定义扩展的情况下如何做到这一点?
You can use the extension Command Variable .您可以使用扩展命令变量。
It can read the content of a file and use it as variable in the launch.json
它可以读取文件的内容并将其用作启动中的变量
launch.json
Define a pre-lauch task in the launch configuration.在启动配置中定义预启动任务。
In task.json
define a task that writes the PID to a file and name the task writePID
在
task.json
定义一个将 PID 写入文件的任务并将任务命名为writePID
ps -ef | grep "async uWSGI worker 1" | grep -v grep | awk '{print $2}' > /tmp/PID_py.txt
Change lauch.json
to lauch.json
更改为
{
"version": "0.2.0",
"configurations": [
{
"type": "fb-python",
"request": "attach",
"name": "Attach to a running Python process",
"processId": "${input:readPID}",
"preLaunchTask": "writePID",
"subProcess": true,
"justMyCode": true,
"redirectOutput": true,
"django": true,
"client": "instagram"
}
],
"inputs": [
{
"id": "readPID",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "/tmp/PID_py.txt"
}
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.