The 'out' returned from exec_cmds is not 'None' type if stderr occurs, it
is
because utils pass 'subprocess.PIPE' to stdout to open this subprocess.
"Similarly, to get anything other than None in the result tuple, you need to
give stdout=PIPE and/or stderr=PIPE too."
(see
http://docs.python.org/2/library/subprocess.html#module-subprocess)
Finally, make out equals to err when stderr happened.
---
utils/utils.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/utils/utils.py b/utils/utils.py
index 147c1ef..2248ce1 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -404,14 +404,12 @@ def exec_cmd(command, sudo=False, cwd=None, infile=None,
outfile=None, shell=Fal
command = ["sudo"] + command
if infile == None:
infile = subprocess.PIPE
- if outfile == None:
- outfile = subprocess.PIPE
p = subprocess.Popen(command, shell=shell, close_fds=True, cwd=cwd,
stdin=infile, stdout=outfile, stderr=subprocess.PIPE)
(out, err) = p.communicate(data)
if out == None:
- # Prevent splitlines() from barfing later on
- out = ""
+ # Because stderr is PIPE, err will not be None, and can be splitlines.
+ out = err
return (p.returncode, out.splitlines())
def remote_exec_pexpect(hostname, username, password, cmd):
--
1.8.3.1