API¶
-
class
procrunner.
ReturnObject
(exitcode=None, command=None, stdout=None, stderr=None, **kw)[source]¶ Bases:
subprocess.CompletedProcess
A subprocess.CompletedProcess-like object containing the executed command, stdout and stderr (both as bytestrings), and the exitcode. The check_returncode() function raises an exception if the process exited with a non-zero exit code.
-
procrunner.
run
(command, timeout=None, debug=None, stdin=None, print_stdout=True, print_stderr=True, callback_stdout=None, callback_stderr=None, environment=None, environment_override=None, win32resolve=True, working_directory=None, raise_timeout_exception=False)[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. (deprecated)
- 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.
- raise_timeout_exception (boolean) – Forward compatibility flag. If set then a subprocess.TimeoutExpired exception is raised instead of returning an object that can be checked for a timeout condition. Defaults to False, will be changed to True in a future release.
Returns: The exit code, stdout, stderr (separately, as byte strings) as a subprocess.CompletedProcess object.