Reputation: 181
In Wondows7 64. I want to get application name from python.
here is code that I can get Processes name,but it's not I want.
from psutil import process_iter
process = filter(lambda p: p.name() == "main2.exe", process_iter())
Upvotes: 2
Views: 5162
Reputation: 855
Maybe you mean this, which gives you the name of the Python script that is running:
import os
print(os.path.splitext(os.path.basename(__file__))[0])
Upvotes: 1
Reputation: 80
On Windows, you could make a system call:
import subprocess
cmd = 'WMIC PROCESS get Caption'
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
for line in proc.stdout:
print line
You could also get the 'Commandline' or 'Processid' if the 'Caption' isn't enough.
Upvotes: 3