I'm trying make python program which waits to process to open and then it does few things,
in my case those "few things" will be in function named action().
I'm a little complicated with this, here's what I did until now.
I've found that function which checks if process is running from the tasklist.exe
def isWindowsProcessRunning( exeName ) :
import subprocess
process = subprocess.Popen(
'tasklist.exe /FO CSV /FI "IMAGENAME eq %s"' % exeName,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True )
out, err = process.communicate()
try : return out.split("\n")[1].startswith('"%s"' % exeName)
except : return False
And I thought to use that in that way:
if( isWindowsPrecessRunning("chrome.exe") == False ):
print "Waiting for chrome to open.."
while( True ):
if( isWindowsPrecessRunning("chrome.exe") == True ):
action()
else:
print "Chrome must be closed when the program starts, please close chrome, and re-open the program"
The problem is that the program was built with "tkinter" for windows,
and while I turn it on once, and chrome isn't running - the program gets into endless loop.
That endless loop, prevent the user of the program to do anything, because it opens a clear cmd, and closes it, opens it, closes it and so over- the user can't even close it.
Does anyone have an idea about how to do it?
Thanks in advance :)