API

class procrunner.ReturnObject(*arg, **kw)[source]

Bases: dict, subprocess.CompletedProcess

A subprocess.CompletedProcess-like object containing the executed command, stdout and stderr (both as bytestrings), and the exitcode. Further values such as process runtime can be accessed as dictionary values. The check_returncode() function raises an exception if the process exited with a non-zero exit code.

procrunner.run(command, timeout=None, debug=False, stdin=None, print_stdout=True, print_stderr=True, callback_stdout=None, callback_stderr=None, environment=None, environment_override=None, win32resolve=True, working_directory=None)[source]

Run an external process.

File system path objects (PEP-519) are accepted in the command, environment, and working directory arguments.

Parameters:
  • command (array) – Command line to be run, specified as array.
  • timeout – Terminate program execution after this many seconds.
  • debug (boolean) – Enable further debug messages.
  • stdin – Optional bytestring that is passed to command stdin.
  • print_stdout (boolean) – Pass stdout through to sys.stdout.
  • print_stderr (boolean) – Pass stderr through to sys.stderr.
  • callback_stdout – Optional function which is called for each stdout line.
  • callback_stderr – Optional function which is called for each stderr line.
  • environment (dict) – The full execution environment for the command.
  • environment_override (dict) – Change environment variables from the current values for command execution.
  • win32resolve (boolean) – If on Windows, find the appropriate executable first. This allows running of .bat, .cmd, etc. files without explicitly specifying their extension.
  • working_directory (string) – If specified, run the executable from within this working directory.
Returns:

A ReturnObject() containing the executed command, stdout and stderr (both as bytestrings), and the exitcode. Further values such as process runtime can be accessed as dictionary values.