Files
deb-python-dcos/cli/dcoscli/common.py
Kyryl Truskovskyi 8cad17dca0 [ADD] DCOS-1323
[FIX] add new line

[FIX] change check
2015-08-20 23:27:28 +03:00

29 lines
757 B
Python

import subprocess
def exec_command(cmd, env=None, stdin=None):
"""Execute CLI command
:param cmd: Program and arguments
:type cmd: [str]
:param env: Environment variables
:type env: dict
:param stdin: File to use for stdin
:type stdin: file
:returns: A tuple with the returncode, stdout and stderr
:rtype: (int, bytes, bytes)
"""
process = subprocess.Popen(
cmd,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env)
# This is needed to get rid of '\r' from Windows's lines endings.
stdout, stderr = [std_stream.replace(b'\r', b'')
for std_stream in process.communicate()]
return (process.returncode, stdout, stderr)