Module gplately.ptt.utils.call_system_command

Functions

def call_system_command(args, check_return_code=0, raise_errors=True, print_errors=True, stdin=None, return_stdout=False, return_stderr=False, **subprocess_options)

Function to call a command on the system (based on 'subprocess' module).

  • Option to check return code of command and which return code to check (defaults to checking code 0 for success).
  • Option to raise error or return False on failure (raises by default).
  • Option to print an error message to stderr on failure (prints by default).
  • Option to pass a stdin string to the standard input of command (not passed by default).
  • Option to receive stdout/stderr strings from the standard output/error of command (not received by default).
  • Optionally pass advanced parameters to 'subprocess.Popen()' such as 'shell=True' (no advanced parameters passed by default).

On success:

  • Returns (stdout, stderr) tuple of strings if 'return_stdout' and 'return_stderr' are True,
  • else returns stdout string if only 'return_stdout' is True,
  • else returns stderr string if only 'return_stderr' is True,
  • else returns True (if both 'return_stdout' and 'return_stderr' are False).

On failure:

  • Raises an exception if 'raise_errors' is True,
  • else returns None (which can be tested as if it was 'False').