Skip to content

Instantly share code, notes, and snippets.

@N-McA
Created January 27, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N-McA/62d19683d87a1b2d67e76a1ffebf2661 to your computer and use it in GitHub Desktop.
Save N-McA/62d19683d87a1b2d67e76a1ffebf2661 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
import shlex
import os
from pathlib import Path
def chdir_to_script_location():
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
def run(cmd, ignore_fail=False):
check = not ignore_fail
return subprocess.run(
shlex.split(cmd), check=check, stdout=subprocess.PIPE
).stdout.decode("UTF-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment