This package provides a Pythonic alternative to `subprocess.run` that captures the output of a child process while simultaneously printing it to the console in real-time, mimicking the behavior of the `tee` command. It is designed for long-running processes where instant feedback is desirable. The current version is 0.4.2 and it maintains a stable release cadence.
pip install subprocess-teeVerified import paths — ran on the pinned version, not inferred.
The `run` function is designed to be a drop-in replacement for `subprocess.run`. By default, it prints output to `sys.stdout` and `sys.stderr` while also capturing it. Use `tee=False` to disable real-time printing if only output capture is needed. The `check=True` argument will raise a `CalledProcessError` on non-zero exit codes, similar to `subprocess.run`.
Be aware that `stdout` and `stderr` attributes of the `CompletedProcess` object will contain strings, not bytes. If binary output is strictly required, `subprocess-tee` might not be the most suitable tool or may require careful handling of encoding.
On Windows, consider using `shell=True` with caution (see next warning) or ensure commands are simple strings. Test extensively for complex argument scenarios on Windows environments.
If child processes are expected to produce non-UTF-8 output, ensure they are configured to use UTF-8 or be prepared to handle potential encoding issues programmatically. There is currently no direct `encoding` parameter in `subprocess-tee.run` to override the default text handling.
Avoid `shell=True` when executing commands with external or untrusted input. Prefer passing commands as a list of arguments (`['command', 'arg1', 'arg2']`) to bypass the shell.
Use `import subprocess_tee` in your Python code.
Handle the exception using a `try...except subprocess_tee.CalledProcessError` block, or explicitly pass `check=False` to `subprocess_tee.run()` if you intend to ignore non-zero exit codes.
Ensure consistency: if `text=True` (default for `subprocess_tee`), `result.stdout` is a string. If `text=False`, `result.stdout` is bytes and needs decoding (e.g., `result.stdout.decode('utf-8')`) before string operations, or ensure you are passing bytes where expected.Use the `input` keyword argument, passing the input as a string (if `text=True`) or bytes (if `text=False`): `subprocess_tee.run(command, input='my input data', text=True)`.
No dependency data recorded yet.