upsies.utils.subproc

Execute external commands

Functions

upsies.utils.subproc.run(argv, *, ignore_errors=False, join_stderr=False, return_exitcode=False, communicate=False)[source]

Execute command in subprocess

Parameters:
  • argv (list of str) – Command to execute

  • ignore_errors (bool) – Do not raise ProcessError if stderr is non-empty

  • join_stderr (bool) – Redirect stderr to stdout

  • return_exitcode (bool) – Return a 2-tuple of (stdout, exitcode) instead of only stdout

  • communicate (bool) – Instead of the command’s output, return a Process instance

Raises:
Returns:

Output from process

Return type:

str

Classes

class upsies.utils.subproc.Process(popen)[source]

Bases: object

Convenience wrapper around subprocess.Popen

The main benefit of it is that you can easily iterate over lines on stdout or stderr.

property stdout

Iterator that yields lines from standard output

If there is nothing to read, an empty string is yielded after a short timeout to prevent your loop from being blocked.

property stderr

Iterator that yields lines from standard error or nothing if standard error is redirected to standard out.

If there is nothing to read, an empty string is yielded after a short timeout to prevent your loop from being blocked.

property is_running

Whether the process is still running

terminate()[source]

Ask process to terminate (SIGTERM) and kill it (SIGKILL) if it doesn’t do that after 1 second

This method does nothing if the process is not running.

property exitcode

Exit code or termination signal after process ended

See subprocess.Popen.returncode