Forum Discussion

DSmachineWorld's avatar
DSmachineWorld
Contributor
5 months ago

Closing multiple processes with same name

I am using this Python script to close a desktop process so TestComplete can proceed. It works fine with a single process of name "foo".

def close_foo():
  # Obtains the foo process and closes it
  p = None
  
  p = Sys.WaitProcess("foo", 500)
  if (p.Exists):
    Log.Message("close_foo: Closing foobar")
    p.Close()
  else:
    Log.Message("close_foo: foobar not running")

  # Checks whether the process is closed
  if (p.Exists):
  # Terminates the process
      p.Terminate()
      Log.Message("close_foo: Terminated foobar")

However, the desktop application can behave badly and launch multiple instances of a process named "foo". How can I loop through existing processes until all are closed?