2

I'm writing a program to monitor a python script running. There will be multiple instances of this script, which is a server, running from different locations on the computer. My program will be monitoring to see that all instances that are being "watched" are up and running and will restart them as necessary.

The server script cannot be edited.

My problem is that the server process just shows up as the python executable, and I am unable to determine the location of the specific server script on the computer.

Is there anyway to determine what script is actually running on a specific python/pythonw.exe process? And also its path?

ENV: Windows only

1 Answer 1

2

You can run the following command from the command line:

WMIC PROCESS get Caption,Commandline,Processid,ExecutablePath

This will show you which module is being executed.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much for the response! This definitely shows the module executing, but is there any way to see its path? The script file will be non unique so I need to determine the exact path.
@Ben You should run your module using the full path. Then, wmic will show you it. For example: python c:\my\python\module.py
Unfortunately the module is started by a batch script that I cannot edit (its a separate piece of software being developed independently). The batch file ends up calling it similar to this "c:\python27\python.exe init.py" w/ the batch file being in the same directory as the init.py. Any ideas? Thanks again.
Try to add ExecutablePath (see the updated answer) if it helps. Actually, you can try to check if your batch file is running instead of checking the python interpreter.
ExecutablePath returns the python exe location. I may be able to use my own batch script and I just tested it calling with the full path and it definitely works w/ WMIC. Thank you again for your help. I will explore my options. I'm going to leave the question open for a while to see if anyone else has an idea, but I will accept it by the end of the day if not! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.