I put together a script with the purpose of checking every 5 minutes if a program was running, and to open it if it was not. The program works fine in Python 2.7.10, but not in Python 3.7.3. In the latest version I get the following error for the last_line = output.strip().split('\r\n')[-1]
line of code :
TypeError: a bytes-like object is required, not 'str'.
I’m not a programmer and made the script by grabbing pieces from here and there, so could anyone help me edit the script for Python 3.7.3?
Here is my code :
import datetime, os, subprocess, time
startTime = datetime.datetime.now()
endTime = datetime.datetime.now() + datetime.timedelta(hours = 3)
while datetime.datetime.now() < endTime:
time.sleep(300)
process_name = 'Epaswmm5.exe'
call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name
output = subprocess.check_output(call)
last_line = output.strip().split('\r\n')[-1]
print(str(datetime.datetime.now()) + " - " + str(last_line.lower().startswith(process_name)))
if last_line.lower().startswith(process_name) == False:
os.startfile("C:\Program Files (x86)\EPA SWMM 5.1\Epaswmm5.exe")