1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 07:36:23 -07:00

Catch KeyboardInterrupt exception in run_cmd and return normally

This commit is contained in:
Eggbertx 2023-05-13 23:56:19 -07:00
parent caaae0c547
commit 4949ccd1d4

View file

@ -149,6 +149,7 @@ def run_cmd(cmd, print_output=True, realtime=False, print_command=False):
status = 0
if realtime: # print the command's output in real time, ignores print_output
while True:
try:
realtime_output = proc.stdout.readline().decode("utf-8")
if realtime_output == "" and status is not None:
return ("", status)
@ -156,6 +157,8 @@ def run_cmd(cmd, print_output=True, realtime=False, print_command=False):
print(realtime_output.strip())
output += realtime_output
status = proc.poll()
except KeyboardInterrupt as e:
return (output, 0)
else: # wait until the command is finished to print the output
output = proc.communicate()[0]
if output is not None: