Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Command:
- def __init__(self):
- self.load_params()
- self.script_path = os.path.dirname(os.path.abspath(__file__))
- self.current_path=os.path.abspath(os.curdir)
- def sh(self, args, print_output=True, shell=True, cwd=None):
- try:
- try:
- print(args)
- if cwd != None:
- os.chdir(cwd)
- else:
- if self.current_path == os.getcwd():
- os.chdir(os.path.abspath(os.path.curdir))
- else:
- os.chdir(os.path.abspath(self.current_path))
- p = subprocess.Popen(args=args.split(), encoding='utf-8', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell, cwd=cwd)
- out, err = p.communicate()
- p.stdout.close()
- if out:
- print(out)
- if err:
- print(err)
- return out
- except Exception as e:
- print(e)
- return subprocess.check_output(args, shell=shell).decode('utf-8')
- except OSError as ex:
- print(ex)
- sys.exit(32)
- def sh_inline(self, args, print_output=True, shell=True):
- try:
- return self.sh(args, print_output=print_output, shell=shell).replace('\n','')
- except OSError as ex:
- print(ex)
- sys.exit(32)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement