backport check_output for 2.6
This commit is contained in:
parent
22ac81650d
commit
69a78db3b3
5 changed files with 34 additions and 6 deletions
|
|
@ -18,7 +18,7 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
__all__ = ['unicode', 'long', 'basestring']
|
||||
__all__ = ['unicode', 'long', 'basestring', 'check_output']
|
||||
|
||||
|
||||
try:
|
||||
|
|
@ -35,3 +35,25 @@ try:
|
|||
basestring = basestring
|
||||
except NameError:
|
||||
basestring = str
|
||||
|
||||
|
||||
try:
|
||||
from subprocess import check_output
|
||||
except ImportError:
|
||||
import subprocess
|
||||
|
||||
def check_output(*popenargs, **kwargs):
|
||||
r"""Run command with arguments and return its output as a byte string.
|
||||
Backported from Python 2.7 as it's implemented as pure python on stdlib.
|
||||
"""
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
error = subprocess.CalledProcessError(retcode, cmd)
|
||||
error.output = output
|
||||
raise error
|
||||
return output
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue