def capture_subprocess(cmd, encoding='<STR_LIT>', **popen_kwargs):
stdout = Pty()  <EOL>stderr = Pipe()<EOL>outputter = Popen(<EOL>cmd,<EOL>stdout=stdout.write,<EOL>stderr=stderr.write,<EOL>**popen_kwargs<EOL>)<EOL>stdout.readonly()  <EOL>stderr.readonly()  <EOL>stdout_tee = Tee(stdout.read, STDOUT)<EOL>stderr_tee = Tee(stderr.read, STDERR)<EOL>exit_code = outputter.wait()<EOL>result = (stdout_tee.join(), stderr_tee.join())<EOL>result = tuple(<EOL>bytestring.decode(encoding)<EOL>for bytestring in result<EOL>)<EOL>if exit_code == <NUM_LIT:0>:<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>error = CalledProcessError(exit_code, cmd)<EOL>error.result = result<EOL>raise error<EOL><DEDENT>
Run a command, showing its usual outputs in real time,
    and return its stdout, stderr output as strings.

    No temporary files are used.