# Path: elbepack/log.py
# def async_logging(r, w, stream, block, atmost=4096):
#     t = threading.Thread(target=AsyncLogging(atmost, stream, block),
#                          args=(r, w))
#     t.daemon = True
#     t.start()


import os
import logging
from subprocess import Popen, PIPE, STDOUT, call
from io import TextIOWrapper, BytesIO
from elbepack.log import async_logging
    ...
    elbepack.shellhelper.CommandError: ...

    >>> get_command_out("false", allow_fail=True)
    b''

    >>> get_command_out("cat -", stdin=b"ELBE", env_add={"TRUE":"true"})
    b'ELBE'

    >>> get_command_out("cat -", stdin="ELBE", env_add={"TRUE":"true"})
    b'ELBE'
    """

    new_env = os.environ.copy()

    if env_add:
        new_env.update(env_add)

    if isinstance(stdin, str):
        stdin = stdin.encode()

    logging.info(cmd, extra={"context":"[CMD] "})

    r, w = os.pipe()

    if stdin is None:
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=w, env=new_env)
    else:
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=w, env=new_env)


# Path: elbepack/log.py
# def async_logging(r, w, stream, block, atmost=4096):
#     t = threading.Thread(target=AsyncLogging(atmost, stream, block),
#                          args=(r, w))
#     t.daemon = True
#     t.start()


# Path: elbepack/shellhelper.py
import os
import logging
from subprocess import Popen, PIPE, STDOUT, call
from io import TextIOWrapper, BytesIO
from elbepack.log import async_logging

    ...
    elbepack.shellhelper.CommandError: ...

    >>> get_command_out("false", allow_fail=True)
    b''

    >>> get_command_out("cat -", stdin=b"ELBE", env_add={"TRUE":"true"})
    b'ELBE'

    >>> get_command_out("cat -", stdin="ELBE", env_add={"TRUE":"true"})
    b'ELBE'
    """

    new_env = os.environ.copy()

    if env_add:
        new_env.update(env_add)

    if isinstance(stdin, str):
        stdin = stdin.encode()

    logging.info(cmd, extra={"context":"[CMD] "})

    r, w = os.pipe()

    if stdin is None:
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=w, env=new_env)
    else:
        p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=w, env=new_env)


    async_logging(r, w, soap, log)