views:

92

answers:

5

I am wondering, is there a way to change the name of a script so that it is not called "python.exe" in the tasklist. The reason I am asking is that I am trying to make a batch file that run's a python script. I want the batch file to check to see if the script is already running. if the script is already running then the batch file will do nothing. Thanks

+1  A: 

Maybe you can try this : http://code.google.com/p/procname/

Peter Tillemans
A: 

This library does not work on Windows, and shouldn't be used in production code. Manipulation the argv array is a rather dirty hack.

Generally I'd not try to identify processes by scanning the process table. This is not really reliable, as process names aren't guaranteed to be unique. Instead I'd spawn a simple server on localhost inside the python script. If started, the script can then try to connect to the server, and quit, if the server is already running. This approach can later on also be expanded to support any kind of IPC.

lunaryorn
A: 

You could use py2exe to convert the Python script to a .exe file which means you could then give it any name you like.

Alternatively you could use Python itself (rather than a .bat file) using the approaches given at http://stackoverflow.com/questions/440932/reading-command-line-arguments-of-another-process-win32-c-code to determine the name of the scripts being run by the 'python.exe' processes.

msanders
A: 

I'd simply create a lockfile in the local filesystem and exit if this exists already.

jhwist
A: 

Copy python.exe to a file name of your choice.

C:\Python26>copy python.exe my_proc.exe
        1 file(s) copied.

C:\Python26>my_proc.exe
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

In the tasklist it is showing as my_proc.exe.

I've tried to make a symlink of python.exe (mklink in Windows 7). Unfortunately it is still showing as python.exe in the task list.

Wai Yip Tung