Get tasklist.exe output

I can’t think of a way to get running tasks on the ignition gateway on windows. Can’t seem import psutil or get stdout from system.util.execute. Anybody got anything? I have a process that needs to be started if it is not running for some reason, and want to check first obviously.

Check out ProcessBuilder.

Check this https://www.blog.pythonlibrary.org/2010/10/03/how-to-find-and-list-all-running-processes-with-python/
At the end of the article, you’ll find “The Cross-Platform Solution!”.

Hope this will help you out

Cheers,

That won’t work. psutil does not exist in Jython.

kwj, you will have to invoke a native task manager app and pull the results back using ProcessBuilder.

1 Like

This is a script I made for an old project.
It checks if a specific process is running or not. ( in this case I put chrome.exe as an example )

[code]import subprocess

def processExists(processname):
command = ‘TASKLIST’, ‘/FI’, ‘imagename eq %s’ % processname
# shell=True hides the shell window, stdout to PIPE enables communicate() to get the tasklist command result
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
# trimming it to the actual lines with information
process_out = process.communicate()[0].strip().split(’\r\n’)
# if TASKLIST returns single line without processname: it’s not running
if len(process_out) > 1 and processname in process_out[-1]:
print(‘process “%s” is running!’ % processname)
return True
else:
print(‘process “%s” is NOT running!’ % processname)
return False

processExists(‘chrome.exe’) [/code]

2 Likes

This is perfect. Thank you very much.