From db0209043672c8c07fa41d5fe6bae119d9a595b8 Mon Sep 17 00:00:00 2001 From: L0laapk3 Date: Sun, 24 Feb 2019 00:33:20 +0100 Subject: [PATCH] Avoid using os.system --- auto.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/auto.py b/auto.py index 67ba62e..9a18eeb 100644 --- a/auto.py +++ b/auto.py @@ -26,20 +26,6 @@ def auto(*args): - def kill(pid): - if psutil.pid_exists(pid): - print("killing factorio") - - if os.name == 'nt': - os.system(f"taskkill /pid {pid}") - else: - os.system(f"kill {pid}") - - while psutil.pid_exists(pid): - time.sleep(0.1) - - time.sleep(0.1) - def printErase(arg): @@ -52,6 +38,22 @@ def printErase(arg): + def kill(pid): + if psutil.pid_exists(pid): + + if os.name == 'nt': + cmd = ("taskkill", "/pid", str(pid)) + else: + cmd = ("kill", str(pid)) + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, shell=True) + + while psutil.pid_exists(pid): + time.sleep(0.1) + + printErase("killed factorio") + + time.sleep(0.1) + def parseArg(arg): if arg[0:2] != "--": @@ -174,9 +176,10 @@ def parseArg(arg): def linkDir(src, dest): if os.name == 'nt': - subprocess.call(("MKLINK", "/J", os.path.abspath(src), os.path.abspath(dest)), shell=True) + cmd = ("MKLINK", "/J", os.path.abspath(src), os.path.abspath(dest)) else: - subprocess.call(("ln", "-s", os.path.abspath(src), os.path.abspath(dest)), shell=True) + cmd = ("ln", "-s", os.path.abspath(src), os.path.abspath(dest)) + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, shell=True) print("enabling FactorioMaps mod") modListPath = os.path.join(kwargs["modpath"], "mod-list.json") if "modpath" in kwargs else "../mod-list.json"