mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-23 02:02:20 +03:00
util fixes
This commit is contained in:
parent
40bf1c3666
commit
22f11cfc3f
1 changed files with 15 additions and 4 deletions
|
@ -115,9 +115,18 @@ class Util:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def execute(command):
|
def execute(command, stdin=None, env=None, cwd=None, shell=True):
|
||||||
p = subprocess.Popen(command, shell=True)
|
|
||||||
return p.wait()
|
try:
|
||||||
|
process = subprocess.Popen(command, stdin=stdin, env=env, cwd=cwd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=shell)
|
||||||
|
|
||||||
|
result_code = process.wait()
|
||||||
|
p_out = ', '.join([str(x) for x in process.stdout.readlines()])
|
||||||
|
p_err = ', '.join([str(x) for x in process.stderr.readlines()])
|
||||||
|
|
||||||
|
return result_code, p_out, p_err
|
||||||
|
except Exception as e:
|
||||||
|
return 1, 'Could not execute command: {0}. Error Message: {1}'.format(command, str(e)), ''
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def execute_script(script_path, parameters=None):
|
def execute_script(script_path, parameters=None):
|
||||||
|
@ -174,3 +183,5 @@ class Util:
|
||||||
return grp.getgrgid(gid)[0]
|
return grp.getgrgid(gid)[0]
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue