Discussion:
[Fab-user] combine_stderr is not separating stderr and stdout
cruxpot
2016-02-24 20:01:37 UTC
Permalink
I'm having an issue getting run and sudo to separate the streams which is
causing issues particularly where sudo presents a first time "lecture"
banner or an error before it runs the command and produces expected output.
In this case, the sudo error is a resolution error on a debian 7 host
running 'whoami'. I have set env.combine_stderr globally (env set at
beginning), "with settings" and as a kwargs argument for sudo(). Same
result, everything goes to stdout no matter I do.

combine_stderr: 'False'
[***@debian7_x64:22] sudo: busybox whoami
[***@debian7_x64:22] out: sudo: unable to resolve host debian7_x64
[***@debian7_x64:22] out: sudo password:
[***@debian7_x64:22] out: root
[***@debian7_x64:22] out:
cmd: 'sudo -S -p 'sudo password:' bash -l -c "cd /tmp/tmpdir2 >/dev/null
&& export PATH=\"\".:/tmp/tmpdir2:/bin:/usr/bin\"\" && whoami"' SUCCEEDED
with return code: '0', output:
sudo: unable to resolve host debian7_x64


Return values (result.stdout and result.stderr) are:

stdout: 'sudo: unable to resolve host debian7_x64

root'
stderr: ''

The "unable to resolve host" should go into stderr and I have confirmed
this manually on a shell that it is in fact stderr. Why is this not
working? It causes parsing issues as I want to discard the error output. I
know the box is misconfigured but that is on purpose (simply remove its
host definition in /etc/hosts).

Code:
with settings(combine_stderr=False):
logger.debug("combine_stderr: '%s'" % env.combine_stderr)
result = sudo(cmd, combine_stderr=False)
Jeff Forcier
2016-02-24 21:42:00 UTC
Permalink
You need to also make sure you set pty=False, otherwise the pseudo-tty
allocated for your remote command will be merging the two streams on
its end anyways.

See the docs which go into detail about the two settings & how they
intersect / why they exist:
http://docs.fabfile.org/en/1.10/usage/interactivity.html#combining-the-two
Post by cruxpot
I'm having an issue getting run and sudo to separate the streams which is
causing issues particularly where sudo presents a first time "lecture"
banner or an error before it runs the command and produces expected output.
In this case, the sudo error is a resolution error on a debian 7 host
running 'whoami'. I have set env.combine_stderr globally (env set at
beginning), "with settings" and as a kwargs argument for sudo(). Same
result, everything goes to stdout no matter I do.
combine_stderr: 'False'
cmd: 'sudo -S -p 'sudo password:' bash -l -c "cd /tmp/tmpdir2 >/dev/null &&
export PATH=\"\".:/tmp/tmpdir2:/bin:/usr/bin\"\" && whoami"' SUCCEEDED with
sudo: unable to resolve host debian7_x64
stdout: 'sudo: unable to resolve host debian7_x64
root'
stderr: ''
The "unable to resolve host" should go into stderr and I have confirmed this
manually on a shell that it is in fact stderr. Why is this not working? It
causes parsing issues as I want to discard the error output. I know the box
is misconfigured but that is on purpose (simply remove its host definition
in /etc/hosts).
logger.debug("combine_stderr: '%s'" % env.combine_stderr)
result = sudo(cmd, combine_stderr=False)
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org
Loading...