Package: runs
runshas improved versions ofcall(),check_call(),check_output(),
andrun()from Python’ssubprocessmodule that handle multiple commands and
blocks of text, fix some defects, and add some features.importrunsruns('''
    ls
    df -k  # or perhaps -h?
    echo 'Done and done'
''')—subprocessis essential but:You can only run one command at a timeCommands to subprocess must be either a sequence of strings or a string,
depending on whethershell=Trueor notResults are returned by default as bytes and not strings—Therunsfunctions let you run a block of text as a sequence of subprocess
calls.runsprovides call-compatible replacements for the functionssubprocess.call(),subprocess.check_call(),subprocess.check_output(),
andsubprocess.run()Each replacement function takes a block of text, which is split into individual
command lines, or a list of commands, and returns a list of values, one for
each command.  A block of text can contain line continuations, and comments,
which are ignored.The replacement functions also add optional logging, error handling,
and lazy evaluation, and use UTF-8 encoding by default.The modulerunsis callable -runs()is a synonym forruns.run().EXAMPLES:# ``runs()`` or ``runs.run()`` writes to stdout and stderr just as if you'd run# the commands from the terminalimportrunsruns('echo "hello, world!"')# prints hello, world!# runs.check_output() returns a list, one string result for each commandresults=check_output('''
    echo  line   one  # Here's line one.
    echo   'line "  two  "'  # and two!
''')assertresults==['line one','line "  two  "']# Line continuations work too, either single or doubleruns('''
    ls -cail

    # One command that takes many lines.
    g++ -DDEBUG  -O0 -g -std=c++17 -pthread -I ./include -lm -lstdc++\-Wall -Wextra -Wno-strict-aliasing -Wpedantic\\-MMD -MP -MF -c src/tests.cpp -o build/./src/tests.cpp.o

    echo DONE
 ''')NOTES:Exactly likesubprocess,runsdiffers from the shell in a few ways, so
you can’t just paste your shell scripts in:Redirection doesn’t work.result=runs.check_output('echo foo > bar.txt')assertresult==['foo > bar.txt\n']Pipes don’t work.result=runs.check_output('echo foo | wc')assertresult==['foo | wc\n']Environment variables are not expanded in command linesresult=runs.check_output('echo $FOO',env={'FOO':'bah!'})assertresult==['$FOO\n']Environment variables are exported to the subprocess, absolutely,
but no environment variable expension happens on command lines.APIruns()runs(commands,*args,iterate=False,encoding='utf8',on_exception=None,echo=False,**kwargs,)(runs.py, 186-200)Callsubprocess.run()on each command.
Return a list ofsubprocess.CompletedProcessinstances.
See the help forsubprocess.run()for more information.Arguments:commands:A string, which gets split into lines on line endings, or a list of
strings.args:Positional arguments tosubprocess.run()(but prefer keyword
arguments!)on_exception:Ifon_exceptionisFalse, the default, exceptions fromsubprocess.run()are raised as usual.Ifon_exceptionis True, they are ignored.Ifon_exceptionis a callable, the line that caused the exception is
passed to it.Ifon_exceptionis a string, the line causing the exception
is printed, prefixed with that string.echo:IfechoisFalse, the default, then commands are silently executed.
IfechoisTrue, commands are printed prefixed with$Ifechois a string, commands are printed prefixed with that string
Ifechois callable, then each command is passed to it.iterate:IfiterateisFalse, the default, then a list of results is
returned.Otherwise an iterator of results which is returned, allowing for lazy
evaluation.encoding:Like the argument tosubprocess.run(), except the default  is'utf8'kwargs:Named arguments passed on tosubprocess.run()runs.call()runs.call(commands,*args,iterate=False,encoding='utf8',on_exception=None,echo=False,**kwargs,)(runs.py, 186-200)Callsubprocess.call()on each command.
Return a list of integer returncodes, one for each command executed.
See the help forsubprocess.call()for more information.Arguments:commands:A string, which gets split into lines on line endings, or a list of
strings.args:Positional arguments tosubprocess.call()(but prefer keyword
arguments!)on_exception:Ifon_exceptionisFalse, the default, exceptions fromsubprocess.call()are raised as usual.Ifon_exceptionis True, they are ignored.Ifon_exceptionis a callable, the line that caused the exception is
passed to it.Ifon_exceptionis a string, the line causing the exception
is printed, prefixed with that string.echo:IfechoisFalse, the default, then commands are silently executed.
IfechoisTrue, commands are printed prefixed with$Ifechois a string, commands are printed prefixed with that string
Ifechois callable, then each command is passed to it.iterate:IfiterateisFalse, the default, then a list of results is
returned.Otherwise an iterator of results which is returned, allowing for lazy
evaluation.encoding:Like the argument tosubprocess.call(), except the default  is'utf8'kwargs:Named arguments passed on tosubprocess.call()runs.check_call()runs.check_call(commands,*args,iterate=False,encoding='utf8',on_exception=None,echo=False,**kwargs,)(runs.py, 186-200)Callsubprocess.check_call()on each command.
If any command has a non-zero returncode, raisesubprocess.CallProcessError.See the help forsubprocess.check_call()for more information.Arguments:commands:A string, which gets split into lines on line endings, or a list of
strings.args:Positional arguments tosubprocess.check_call()(but prefer keyword
arguments!)on_exception:Ifon_exceptionisFalse, the default, exceptions fromsubprocess.check_call()are raised as usual.Ifon_exceptionis True, they are ignored.Ifon_exceptionis a callable, the line that caused the exception is
passed to it.Ifon_exceptionis a string, the line causing the exception
is printed, prefixed with that string.echo:IfechoisFalse, the default, then commands are silently executed.
IfechoisTrue, commands are printed prefixed with$Ifechois a string, commands are printed prefixed with that string
Ifechois callable, then each command is passed to it.iterate:IfiterateisFalse, the default, then a list of results is
returned.Otherwise an iterator of results which is returned, allowing for lazy
evaluation.encoding:Like the argument tosubprocess.check_call(), except the default  is'utf8'kwargs:Named arguments passed on tosubprocess.check_call()runs.check_output()runs.check_output(commands,*args,iterate=False,encoding='utf8',on_exception=None,echo=False,**kwargs,)(runs.py, 186-200)Callsubprocess.check_output()on each command.
If a command has a non-zero exit code, raise asubprocess.CallProcessError.
Otherwise, return the results as a list of strings, one for each command.
See the help forsubprocess.check_output()for more information.Arguments:commands:A string, which gets split into lines on line endings, or a list of
strings.args:Positional arguments tosubprocess.check_output()(but prefer keyword
arguments!)on_exception:Ifon_exceptionisFalse, the default, exceptions fromsubprocess.check_output()are raised as usual.Ifon_exceptionis True, they are ignored.Ifon_exceptionis a callable, the line that caused the exception is
passed to it.Ifon_exceptionis a string, the line causing the exception
is printed, prefixed with that string.echo:IfechoisFalse, the default, then commands are silently executed.
IfechoisTrue, commands are printed prefixed with$Ifechois a string, commands are printed prefixed with that string
Ifechois callable, then each command is passed to it.iterate:IfiterateisFalse, the default, then a list of results is
returned.Otherwise an iterator of results which is returned, allowing for lazy
evaluation.encoding:Like the argument tosubprocess.check_output(), except the default  is'utf8'kwargs:Named arguments passed on tosubprocess.check_output()(automatically generated bydokson 2020-12-16T13:48:26.579866)