Command execution



A subprocess.Popen with superpowers


magicrun(→ MagicPopen)

Run a command, with superpowers

Module Contents

class progfiguration.cmd.MagicPopen(args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=None, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, encoding=None, errors=None, text=None, user=None, group=None, extra_groups=None, umask=-1, pipesize=-1, process_group=None)

Bases: subprocess.Popen

A subprocess.Popen with superpowers

This is a wrapper for subprocess.Popen, which is guaranteed to have a .stdout and .stderr property, which will always be StringIO objects (not bytes).

It’s the return value for magicrun(), and shouldn’t be used elsewhere.

stdout: io.StringIO
stderr: io.StringIO
progfiguration.cmd.magicrun(cmd: str | list, print_output=True, log_output=False, check=True, *args, **kwargs) MagicPopen

Run a command, with superpowers


  • cmd: The command to run. If a string, it will be passed to a shell.

  • print_output: Print the command’s stdout/stderr in to the controlling terminal’s stdout/stderr in real time.

    stdout/stderr is always captured and returned, whether this is True or False (superpowers). The .stdout and .stderr properties are always strings, not bytes (which is required because we must use universal_newlines=True). * <> * <>

  • log_output: Log the command’s stdout/stderr in a single log message (each) after the command completes.

  • check: Raise an exception if the command returns a non-zero exit code.

    Unlike, this is True by default.

  • *args, **kwargs: Passed to subprocess.Popen

    Do not pass the following arguments, as they are used internally: * shell: Determined automatically based on the type of cmd * stdout: Always subprocess.PIPE * stderr: Always subprocess.PIPE * universal_newlines: Always True * bufsize: Always 1

A MagicPopen object is always returned.