Overview
Theerrortrace module provides utilities for executing shell commands with real-time output capture and processing.
Functions
run_command
Executes a shell command and captures stdout, stderr, and return code using threading for non-blocking I/O.Signature
Parameters
Shell command to execute as a string (will be split using
shlex.split())Returns
Implementation Details
- Uses
subprocess.Popenwith separate pipes for stdout and stderr - Creates dedicated threads for reading each output stream
- Non-blocking I/O prevents deadlocks on large outputs
- Strips whitespace from each output line
- Waits for process completion before returning
Example Usage
splat_find
Wrapper function that executes a command and returns output as JSON.Signature
Parameters
Shell command to execute
Returns
JSON string containing command results, or
None if no command provided:Example Usage
Threading Model
Both functions use Python’sthreading module to handle concurrent I/O:
- stdout thread: Continuously reads from process stdout
- stderr thread: Continuously reads from process stderr
- Main thread: Waits for both threads to complete, then retrieves return code
Logging
The module configures logging at ERROR level:Notes
- Commands are safely split using
shlex.split()to handle quoted arguments - Output streams are read with
bufsize=1for line-buffered I/O universal_newlines=Trueensures text mode output- Both functions strip whitespace from output lines
splat_findprints diagnostic information about the command being executed