runcommand#

runcommand(command, printinput=False, printoutput=None, wait=True, **kwargs)[source]#

Make it easier to run shell commands.

Alias to subprocess.Popen(). Returns captured output if wait=True, else returns the subprocess.

Parameters:
  • command (str) – the command to run

  • printinput (bool) – whether to print the input string

  • printoutput (bool) – whether to print the output (default: False if wait=True, True if wait=False)

  • wait (bool) – whether to wait for the process to return (else, return immediately with the subprocess)

Examples:

myfiles = sc.runcommand('ls').split('\n') # Get a list of files in the current folder
sc.runcommand('sshpass -f %s scp myfile.txt me@myserver:myfile.txt' % 'pa55w0rd', printinput=True, printoutput=True) # Copy a file remotely
sc.runcommand('sleep 600; mkdir foo', wait=False) # Waits 10 min, then creates the folder "foo", but the function returns immediately
sc.runcommand('find', wait=False) # Equivalent to executing 'find' in a terminal

New in version 3.1.1: print real-time output if wait=False