[libvirt] [libvirt-test-API][PATCH] Fix utils.exec_cmd output problem
Guannan Ren
gren at redhat.com
Wed Nov 27 06:07:14 UTC 2013
On 2013年11月26日 17:17, Jincheng Miao wrote:
> Thanks for review,
> yes, I missed this situation: stdout is not the subprocess.PIPE.
>
> Since the stderr is always subprocess.PIPE, my another way is err after Popen.communicate().
>
> The patch looks like:
> ---
> utils/utils.py | 2 ++---
> 1 file changed, 2 insertions(+)
>
> diff --git a/utils/utils.py b/utils/utils.py
> index 147c1ef..d107cbd 100644
> --- a/utils/utils.py
> +++ b/utils/utils.py
> @@ -412,6 +412,8 @@ def exec_cmd(command, sudo=False, cwd=None, infile=None, outfile=None, shell=Fal
> 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 = ""
> + if err != "":
> + out += err
> return (p.returncode, out.splitlines())
>
> def remote_exec_pexpect(hostname, username, password, cmd):
Why to append standard error to standard output. It is not right in
semantics.
In order to get the standard error if executing command failed, the
following change is enough:
if out == None:
# Prevent splitlines() from barfing later on
out = ""
+ if p.returncode:
+ out = err
return (p.returncode, out.splitlines())
Guannan
More information about the libvir-list
mailing list