Files
deb-python-dcos/integrations/cli/common.py
José Armando García Sancio 0b0b491fa0 DCOS-364 Implements dcos app start
2015-02-18 20:44:15 +00:00

33 lines
836 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: {!r}'.format(stdout.decode('utf-8')))
print('STDERR: {!r}'.format(stderr.decode('utf-8')))
return (process.returncode, stdout, stderr)