# Testing whether a program is running or not

**URL:** <https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727>\
**Category:** Standard Libraries\
**Created:** [22 August 2024 11:29 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727 "2024-08-22T11:29:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexV](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@AlexV](https://forum.robotframework.org/u/AlexV)\
**Post date:** [22 August 2024 11:29 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/1 "2024-08-22T11:29:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [22 August 2024 14:23 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/2 "2024-08-22T14:23:52Z")

</div>

Hi,

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.

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![AlexV](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@AlexV](https://forum.robotframework.org/u/AlexV)\
**Post date:** [22 August 2024 20:36 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/3 "2024-08-22T20:36:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AlexV](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@AlexV](https://forum.robotframework.org/u/AlexV)\
**Post date:** [22 August 2024 20:37 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/4 "2024-08-22T20:37:53Z")

</div>

It keeps deleting a part of my msg lol.  
I used:  
Is Process Running path to exe  
however it didn’t know what to do with it

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [23 August 2024 08:50 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/5 "2024-08-23T08:50:12Z")

</div>

Hi,

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.

Anyway glad you found a solution 🙂

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![AlexV](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@AlexV](https://forum.robotframework.org/u/AlexV)\
**Post date:** [23 August 2024 10:50 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/6 "2024-08-23T10:50:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [23 August 2024 13:50 UTC](https://forum.robotframework.org/t/testing-whether-a-program-is-running-or-not/7727/7 "2024-08-23T13:50:47Z")

</div>

Hi Alex

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

```
