Skip to content

Commit

Permalink
Avoid using os.system
Browse files Browse the repository at this point in the history
  • Loading branch information
L0laapk3 committed Feb 23, 2019
1 parent addf327 commit db02090
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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] != "--":
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit db02090

Please sign in to comment.