Files
deb-python-dcos/cli/tests/integrations/cli/common.py
José Armando García Sancio 686826b020 dcos-635 refactor package for subcommand
Refactor the packaging so that subcommands can depend on the common
functionality without getting the executable artifacts.
2015-03-20 16:51:30 -07:00

33 lines
832 B
Python

import subprocess
def exec_command(cmd, env=None, stdin=None):
"""Execute CLI command
:param cmd: Program and arguments
:type cmd: list of str
:param env: Environment variables
:type env: dict of str to str
:param stdin: File to use for stdin
:type stdin: file
:returns: A tuple with the returncode, stdout and stderr
:rtype: (int, bytes, bytes)
"""
print('CMD: {!r}'.format(cmd))
process = subprocess.Popen(
cmd,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env)
stdout, stderr = process.communicate()
# We should always print the stdout and stderr
print('STDOUT: {}'.format(stdout.decode('utf-8')))
print('STDERR: {}'.format(stderr.decode('utf-8')))
return (process.returncode, stdout, stderr)