mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #918 from SEJeff/make-cmdrun-easier-in-states
Strip the trailing newline / whitespace from cmd.*
This commit is contained in:
commit
06e210f1c4
@ -46,7 +46,8 @@ def _run(cmd,
|
|||||||
runas=None,
|
runas=None,
|
||||||
with_env=True,
|
with_env=True,
|
||||||
shell=DEFAULT_SHELL,
|
shell=DEFAULT_SHELL,
|
||||||
env=()):
|
env=(),
|
||||||
|
rstrip=True):
|
||||||
'''
|
'''
|
||||||
Do the DRY thing and only call subprocess.Popen() once
|
Do the DRY thing and only call subprocess.Popen() once
|
||||||
'''
|
'''
|
||||||
@ -105,6 +106,16 @@ def _run(cmd,
|
|||||||
proc = subprocess.Popen(cmd, **kwargs)
|
proc = subprocess.Popen(cmd, **kwargs)
|
||||||
|
|
||||||
out = proc.communicate()
|
out = proc.communicate()
|
||||||
|
|
||||||
|
if rstrip:
|
||||||
|
# Cast out to a list as proc.communicate() returns a tuple
|
||||||
|
out = list(out)
|
||||||
|
if out[0]:
|
||||||
|
out[0] = out[0].rstrip()
|
||||||
|
# None lacks a rstrip() method
|
||||||
|
if out[1]:
|
||||||
|
out[1] = out[1].rstrip()
|
||||||
|
|
||||||
ret['stdout'] = out[0]
|
ret['stdout'] = out[0]
|
||||||
ret['stderr'] = out[1]
|
ret['stderr'] = out[1]
|
||||||
ret['pid'] = proc.pid
|
ret['pid'] = proc.pid
|
||||||
|
Loading…
Reference in New Issue
Block a user