Search code examples
pythonpython-3.xparamikoinvokefabric

fabric.api.sudo() returning empty stderr on error condition


I am new to fabric. I am running a command as res = fabric.api.sudo(f"pip install {something}",user=user) I expect the command to return stderr or abort when the package/version is not found i.e. pip install fails. However I am getting a res.return_code=0, res.stderr, as empty on an error condition. I do get the ERROR message on stdout. Is it expected behavior ? How can I make the stderr have the error condition and the correct return_code?

Version: Using Fabric3 with version 1.14.post1

Any help would be great, thanks.


Solution

  • The command had multiple commands with pipes. So needed to leverage PIPESTATUS to get the right return code.