Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Let's say I have a Python script that will use the subprocess library to execute the some basic pm2 commands (for nodejs code) as shown below:

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

The output then comes in a tabular format with all the services that were started/running/errored on the standard output.

How do I get only the relevant data that I want?

For example: If I do the below:

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

I should only get the output for someService

Is there a library in python that will allow me to do this? Or can I hit the pm2 using curl commands from within my Python script?

like image 472
user1452759 Avatar asked Jan 27 '26 12:01

user1452759


1 Answers

After some messing around I have found the answer. A simple pm2 jlist retrieves the output in JSON.

subprocess.call(['pm2', 'jlist'])
like image 148
user1452759 Avatar answered Jan 29 '26 02:01

user1452759



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!