I’m trying to make a Keyword where I am checking to see if a program is running or not.
I use ‘Start Process’ to start the application and it turns it active, however in a later phase I cant be sure its the active process any longer.
I tried using Is Process Running | but it keeps giving an Non-existing index or alias.
I looked further and I seem to be missing how to get the app’s handle correctly.
Any help with that?
Did you give an alias when starting the process?
You can do this:
Start Process ${command} alias=myprocess
# some actions
${is Running} Is Process Running myprocess
Should Be True ${is Running}
Is Process Running uses latest process active if you don’t specify a handle/alias.
You should be able to have it empty if you only have one process, or maybe try also to set it to 0 if you don’t want to use an alias.
I didn’t know about the alias part, will consider it going forward.
My question was more toward a case where I assume I didn’t start the process and it was active beforehand.
I’ve already found a different solution for my issue, but I’d still be happy to know if such a thing is possible.
When I tried ‘Is Process Running | ’ it didn’t know what to do.
OK I see, but unfortunately the library does not work like this.
It is able to get process statuses and infos, but only from the processes started from the library.
Start Process prog1 alias=process1
Start Process prog2 alias=process2
# currently active process is process2
Is Process Running
#Above: checks if process2 is active (last started)
Is Process Running process1
#Above: checks if process1 is active (through alias)
So you can’t use exe path directly.
If the process has been started in an other way, then you will need another solution, probably through OperatingSystem library to get infos on processes with Run Command, or python Psutil Library to get infos through PID.
Thanks for the help.
Unfortunate, but good to know going forward.
I’ll look into the OperatingSystem lib at some point to see how it may serve me going forward.
The below may be helpful, I just took it from an older project of mine
But it returns a process PID by name, it might give you some ideas. Sorry, it’s not a direct answer, but reading above, it looks as though you have a soultion but was just passing through.
import os
import psutil
import win32gui
def get_pid_by_name(sut_name, expectedWindowName):
output = os.popen('wmic process get description, processid').read()
lines = output.splitlines()
for line in lines:
if sut_name in line:
pid = line.split()[-1]
process = psutil.Process(int(pid))
process_name = process.name()
print(f'{sut_name} pid: {pid} name {process_name}')
w = win32gui
found = w.FindWindow(None, expectedWindowName)
if w.GetWindowText(found) != "":
print(w.GetWindowText(found))
return pid
else:
print(f"No match for expected window name: \"{expectedWindowName}\" - Process \"{sut_name}\" "
f"please check expected window name.")
return None