Using a while loop, I throw a command in cmd (windows), which repeats every 60 seconds. At a certain moment, the script that I launched per cmd freezes and the loop is locked. How can the python script interrupt and automatically start the while without importing the status of the cmd?
This would be the code I'm using
# Import time for sleep
import datetime
import time
import os
count = 0
while(True):
os.system('...')
# Fecha
now = datetime.datetime.now()
fecha = now.strftime("%d-%m-%Y %H:%M:%S")
print(fecha + " / Descarga: %d" % (count + 1))
count += 1
time.sleep(60)
UPDATE N1
The problem now is the arguments. First I pass the code of the .py and then a capture of the errors caused by the cmd.
import datetime
import subprocess
import time
d_token = "ewifjweof87ew98f7we"
d_channel = "9809808"
d_date = time.strftime("%d/%m/%Y") ## dd/mm/yyyy format
d_format = "PlainText"
cmd = ["DiscordChatExporter.Cli.exe", "-t", d_token, "-c", d_channel, "-o", "logs-gocrypto.txt", "--datefrom", d_date, "-f", d_format]
timeout = 60
count = 0
while True:
t0 = time.perf_counter()
try:
subprocess.run(cmd, check=True, timeout=timeout, shell=True)
now = datetime.datetime.now()
fecha = now.strftime("%d-%m-%Y %H:%M:%S")
print("{} / Descarga: {}".format(fecha, count + 1))
count += 1
except subprocess.TimeoutExpired:
print("[ERROR] Proceso terminado tras timeout")
except subprocess.CalledProcessError:
print("[ERROR] El proceso no termino correctamente")
finally:
t_restante = timeout - (time.perf_counter() - t0)
if t_restante > 0:
time.sleep(t_restante)