mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Add run_comps
This commit is contained in:
parent
e37431083b
commit
88ca3bd348
@ -45,6 +45,25 @@ def run_stderr(cmd, cwd='/root'):
|
||||
cwd=cwd,
|
||||
stderr=subprocess.PIPE).communicate()[0]
|
||||
|
||||
def run_comps(cmd, cwd='/root'):
|
||||
'''
|
||||
Execute the passed command and return a dict of return data
|
||||
|
||||
CLI Example:
|
||||
salt '*' cmd.run_comps "ls -l | grep foo | awk '{print $2}'"
|
||||
'''
|
||||
ret = {}
|
||||
proc = subprocess.Popen(cmd,
|
||||
shell=True,
|
||||
cwd=cwd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
out = proc.communicate()
|
||||
ret['stdout'] = out[0]
|
||||
ret['stderr'] = out[1]
|
||||
ret['retcode'] = out.returncode
|
||||
return ret
|
||||
|
||||
def retcode(cmd, cwd='/root'):
|
||||
'''
|
||||
Execute a shell command and return the command's return code.
|
||||
|
Loading…
Reference in New Issue
Block a user