def cmd(command, shell=False, detach=False, verbose=<NUM_LIT:0>, tee=None, cwd=None,<EOL>env=None, tee_backend='<STR_LIT>', verbout=None, **kwargs):
if kwargs:  <EOL><INDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', DeprecationWarning)<EOL>tee = kwargs.pop('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', DeprecationWarning)<EOL>detach = kwargs.pop('<STR_LIT>')<EOL><DEDENT>if kwargs:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(list(kwargs.keys)))<EOL><DEDENT><DEDENT>if isinstance(command, six.string_types):<EOL><INDENT>command_text = command<EOL>command_tup = None<EOL><DEDENT>else:<EOL><INDENT>import pipes<EOL>command_tup = command<EOL>command_text = '<STR_LIT:U+0020>'.join(list(map(pipes.quote, command_tup)))<EOL><DEDENT>if shell or sys.platform.startswith('<STR_LIT:win32>'):<EOL><INDENT>args = command_text<EOL><DEDENT>else:<EOL><INDENT>if command_tup is None:<EOL><INDENT>import shlex<EOL>command_tup = shlex.split(command_text)<EOL><DEDENT>args = command_tup<EOL><DEDENT>if tee is None:<EOL><INDENT>tee = verbose > <NUM_LIT:0><EOL><DEDENT>if verbose > <NUM_LIT:1>:<EOL><INDENT>import os<EOL>import platform<EOL>import getpass<EOL>from ubelt import util_path<EOL>if verbose > <NUM_LIT:2>:<EOL><INDENT>try:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>except Exception:  <EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>cwd_ = os.getcwd() if cwd is None else cwd<EOL>compname = platform.node()<EOL>username = getpass.getuser()<EOL>cwd_ = util_path.compressuser(cwd_)<EOL>ps1 = '<STR_LIT>'.format(username, compname, cwd_)<EOL>print(ps1 + command_text)<EOL><DEDENT>def make_proc():<EOL><INDENT>import subprocess<EOL>proc = subprocess.Popen(args, stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE, shell=shell,<EOL>universal_newlines=True, cwd=cwd, env=env)<EOL>return proc<EOL><DEDENT>if detach:<EOL><INDENT>info = {'<STR_LIT>': make_proc(), '<STR_LIT>': command_text}<EOL>if verbose > <NUM_LIT:0>:  <EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if tee:<EOL><INDENT>stdout, stderr = sys.stdout, sys.stderr<EOL>proc, logged_out, logged_err = _tee_output(make_proc, stdout, stderr,<EOL>backend=tee_backend)<EOL>try:<EOL><INDENT>out = '<STR_LIT>'.join(logged_out)<EOL><DEDENT>except UnicodeDecodeError:  <EOL><INDENT>out = '<STR_LIT:\n>'.join(_.decode('<STR_LIT:utf-8>') for _ in logged_out)<EOL><DEDENT>try:<EOL><INDENT>err = '<STR_LIT>'.join(logged_err)<EOL><DEDENT>except UnicodeDecodeError:  <EOL><INDENT>err = '<STR_LIT:\n>'.join(_.decode('<STR_LIT:utf-8>') for _ in logged_err)<EOL><DEDENT>(out_, err_) = proc.communicate()<EOL><DEDENT>else:<EOL><INDENT>proc = make_proc()<EOL>(out, err) = proc.communicate()<EOL><DEDENT>ret = proc.wait()<EOL>info = {<EOL>'<STR_LIT>': out,<EOL>'<STR_LIT>': err,<EOL>'<STR_LIT>': ret,<EOL>'<STR_LIT>': proc,<EOL>'<STR_LIT>': cwd,<EOL>'<STR_LIT>': command_text<EOL>}<EOL>if verbose > <NUM_LIT:2>:<EOL><INDENT>try:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>except Exception:  <EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>return info<EOL>
Executes a command in a subprocess.

The advantage of this wrapper around subprocess is that
(1) you control if the subprocess prints to stdout,
(2) the text written to stdout and stderr is returned for parsing,
(3) cross platform behavior that lets you specify the command as a string
or tuple regardless of whether or not shell=True.
(4) ability to detach, return the process object and allow the process to
run in the background (eventually we may return a Future object instead).

Args:
    command (str or Sequence): bash-like command string or tuple of
        executable and args

    shell (bool): if True, process is run in shell, defaults to False.

    detach (bool): if True, process is detached and run in background,
        defaults to False.

    verbose (int): verbosity mode. Can be 0, 1, 2, or 3. Defaults to 0.

    tee (bool, optional): if True, simultaneously writes to stdout while
        capturing output from the command. If not specified, defaults to
        True if verbose > 0.  If detech is True, then this argument is
        ignored.

    cwd (PathLike, optional): path to run command

    env (str, optional): environment passed to Popen

    tee_backend (str, optional): backend for tee output.
        Valid choices are: "auto", "select" (POSIX only), and "thread".

    **kwargs: only used to support deprecated arguments

Returns:
    dict: info - information about command status.
        if detach is False `info` contains captured standard out,
        standard error, and the return code
        if detach is False `info` contains a reference to the process.

Notes:
    Inputs can either be text or tuple based. On UNIX we ensure conversion
    to text if shell=True, and to tuple if shell=False. On windows, the
    input is always text based.  See [3] for a potential cross-platform
    shlex solution for windows.

CommandLine:
    python -m ubelt.util_cmd cmd
    python -c "import ubelt as ub; ub.cmd('ping localhost -c 2', verbose=2)"

References:
    [1] https://stackoverflow.com/questions/11495783/redirect-subprocess-stderr-to-stdout
    [2] https://stackoverflow.com/questions/7729336/how-can-i-print-and-display-subprocess-stdout-and-stderr-output-without-distorti
    [3] https://stackoverflow.com/questions/33560364/python-windows-parsing-command-lines-with-shlex

Example:
    >>> info = cmd(('echo', 'simple cmdline interface'), verbose=1)
    simple cmdline interface
    >>> assert info['ret'] == 0
    >>> assert info['out'].strip() == 'simple cmdline interface'
    >>> assert info['err'].strip() == ''

Doctest:
    >>> info = cmd('echo str noshell', verbose=0)
    >>> assert info['out'].strip() == 'str noshell'

Doctest:
    >>> # windows echo will output extra single quotes
    >>> info = cmd(('echo', 'tuple noshell'), verbose=0)
    >>> assert info['out'].strip().strip("'") == 'tuple noshell'

Doctest:
    >>> # Note this command is formatted to work on win32 and unix
    >>> info = cmd('echo str&&echo shell', verbose=0, shell=True)
    >>> assert info['out'].strip() == 'str' + chr(10) + 'shell'

Doctest:
    >>> info = cmd(('echo', 'tuple shell'), verbose=0, shell=True)
    >>> assert info['out'].strip().strip("'") == 'tuple shell'

Doctest:
    >>> import ubelt as ub
    >>> from os.path import join, exists
    >>> fpath1 = join(ub.get_app_cache_dir('ubelt'), 'cmdout1.txt')
    >>> fpath2 = join(ub.get_app_cache_dir('ubelt'), 'cmdout2.txt')
    >>> ub.delete(fpath1)
    >>> ub.delete(fpath2)
    >>> info1 = ub.cmd(('touch', fpath1), detach=True)
    >>> info2 = ub.cmd('echo writing2 > ' + fpath2, shell=True, detach=True)
    >>> while not exists(fpath1):
    ...     pass
    >>> while not exists(fpath2):
    ...     pass
    >>> assert ub.readfrom(fpath1) == ''
    >>> assert ub.readfrom(fpath2).strip() == 'writing2'
    >>> info1['proc'].wait()
    >>> info2['proc'].wait()