Convenience Functions

This page covers details of additional functions available in the ProcessRunner package.

RunCommand

The RunCommand function returns the process exit code, and stdout and stderr are connected to local stdout and stderr.

Accessed via processrunner.runCommand.

processrunner.runcommand.runCommand(command, outputPrefix='ProcessRunner> ', returnAllContent=False)

Easy invocation of a command with default IO streams

returnAllContent as False (default):

Parameters
  • command (list) – List of strings to pass to subprocess.Popen

  • outputPrefix (str) – String to prepend to all output lines. Defaults to ‘ProcessRunner> ‘

  • returnAllContent (bool) – False (default) sends command stdout/stderr to regular interfaces, True collects and returns them

Returns: int The return code from the command (returnAllContent as False (default)) tuple (return code, list of output) The return code and any output content (returnAllContent as True)

ssh

The ssh function runs a command on a remote host, and returns the SSH exit code. stdout and stderr are connected to local stdout and stderr.

Accessed via processrunner.ssh.

processrunner.ssh.ssh(remoteAddress, remoteCommand, outputPrefix='ssh> ')

Easy invocation of SSH.

Note: Sets StrictHostKeyChecking to “no”.

Parameters
  • remoteAddress (string) – IP or hostname for target system

  • remoteCommand (string) – The command to run on the target system

  • outputPrefix (string) – String to prepend to all output lines. Defaults to ‘ssh> ‘

Returns

int. The SSH exit code (usually the exit code of the executed command)

WriteOut

The WriteOut function is used to prepend lines from the external process with a given string. Given a pipe and a string, it returns a function that accepts a line of text, then writes that line to the provided pipe, prepended with a user provided string. Useful when handling output from processes directly. See example use on the Examples page.

Accessed via processrunner.WriteOut.

processrunner.writeout.writeOut(pipe, outputPrefix)

Use with ProcessRunner.mapLines to easily write to your favorite pipe or handle

Parameters
  • pipe (pipe) – A system pipe/file handle to write output to

  • outputPrefix (string) – A string to prepend to each line

Returns

function

getActiveProcesses

Accessed via processrunner.getActiveProcesses

processrunner.getActiveProcesses()

Retrieve a list of running processes started by ProcessRunner

Returns

list. List of ProcessRunner instances