openlifu.nav.photoscan.subprocess_stream_output

openlifu.nav.photoscan.subprocess_stream_output(args: str | List[str], stdout_handler: Callable[[str], None], stderr_handler: Callable[[str], None], check: bool = True, text: bool = True, **kwargs: Any) CompletedProcess[source]

Run a subprocess and stream its stdout and stderr output to separate handlers/loggers. A drop in replacement for subprocess.run that handles logging.

Parameters:
  • args (Union[str, List[str]]) – Command and arguments to execute. Can be a string or list of strings.

  • stdout_handler (Callable[[str], None]) – Function to handle each line of standard output.

  • stderr_handler (Callable[[str], None]) – Function to handle each line of standard error.

  • check (bool, optional) – If True, raise CalledProcessError if the subprocess exits with a non-zero code.

  • text (bool, optional) – If True, communicate with the process using text mode. Defaults to True.

  • **kwargs (Any) – Additional keyword arguments passed to subprocess.Popen.

Returns:

An object containing the arguments used and the return code.

Return type:

CompletedProcess

Raises:

CalledProcessError – If check is True and the subprocess exits with a non-zero status.