eason
eason

Reputation: 181

How to get application name from python?

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())

enter image description here

Upvotes: 2

Views: 5162

Answers (2)

Carmen DiMichele
Carmen DiMichele

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

user2755334
user2755334

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

Related Questions