如何从 Python 脚本执行节点 js 的 pm2 start/stop/status?

How to perform a pm2 start/stop/status of node js from Python script?

假设我有一个 Python 脚本,它将使用 subprocess 库来执行一些基本的 pm2 命令(对于 nodejs 代码),如下所示:

import subprocess
subprocess.call(['pm2', 'status'])

然后输出以表格格式出现,其中包含标准输出中 started/running/errored 的所有服务。

如何只获取我想要的相关数据?

例如: 如果我执行以下操作:

subprocess.call(['pm2', 'status', 'someService'])

我应该只得到 someService

的输出

python 中是否有允许我执行此操作的图书馆?或者我可以在 Python 脚本中使用 curl 命令访问 pm2 吗?

经过一番折腾,我找到了答案。一个简单的 pm2 jlist 检索 JSON.

中的输出
subprocess.call(['pm2', 'jlist'])