run
Tools to run commands.
Authors:
- Stijn De Weirdt (Ghent University)
- Dries Verdegem (Ghent University)
- Kenneth Hoste (Ghent University)
- Pieter De Baets (Ghent University)
- Jens Timmerman (Ghent University)
- Toon Willems (Ghent University)
- Ward Poelmans (Ghent University)
RunShellCmdError
¶
create_cmd_scripts(cmd_str, work_dir, env, tmpdir, out_file, err_file)
¶
Create helper scripts for specified command in specified directory: - env.sh which can be sourced to define environment in which command was run; - cmd.sh to create interactive (bash) shell session with working directory and environment, and with the command in shell history;
fileprefix_from_cmd(cmd, allowed_chars=False)
¶
Simplify the cmd to only the allowed_chars we want in a filename
PARAMETER | DESCRIPTION |
---|---|
cmd
|
the cmd (string)
|
allowed_chars
|
characters allowed in filename (defaults to string.ascii_letters + string.digits + "_-")
DEFAULT:
|
raise_run_shell_cmd_error(cmd_res)
¶
Raise RunShellCmdError for failed shell command, after collecting additional caller info
run_shell_cmd(cmd, fail_on_error=True, split_stderr=False, stdin=None, env=None, hidden=False, in_dry_run=False, verbose_dry_run=False, work_dir=None, use_bash=True, output_file=True, stream_output=None, asynchronous=False, task_id=None, with_hooks=True, qa_patterns=None, qa_wait_patterns=None, qa_timeout=100)
¶
Run specified (interactive) shell command, and capture output + exit code.
PARAMETER | DESCRIPTION |
---|---|
fail_on_error
|
fail on non-zero exit code (enabled by default)
DEFAULT:
|
split_stderr
|
split of stderr from stdout output
DEFAULT:
|
stdin
|
input to be sent to stdin (nothing if set to None)
DEFAULT:
|
env
|
environment to use to run command (if None, inherit current process environment)
DEFAULT:
|
hidden
|
do not show command in terminal output (when using --trace, or with --extended-dry-run / -x)
DEFAULT:
|
in_dry_run
|
also run command in dry run mode
DEFAULT:
|
verbose_dry_run
|
show that command is run in dry run mode (overrules 'hidden')
DEFAULT:
|
work_dir
|
working directory to run command in (current working directory if None)
DEFAULT:
|
use_bash
|
execute command through bash shell (enabled by default)
DEFAULT:
|
output_file
|
collect command output in temporary output file
DEFAULT:
|
stream_output
|
stream command output to stdout (auto-enabled with --logtostdout if None)
DEFAULT:
|
asynchronous
|
indicate that command is being run asynchronously
DEFAULT:
|
task_id
|
task ID for specified shell command (included in return value)
DEFAULT:
|
with_hooks
|
trigger pre/post run_shell_cmd hooks (if defined)
DEFAULT:
|
qa_patterns
|
list of 2-tuples with patterns for questions + corresponding answers
DEFAULT:
|
qa_wait_patterns
|
list of strings with patterns for non-questions
DEFAULT:
|
qa_timeout
|
amount of seconds to wait until more output is produced when there is no matching question
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Named tuple with: - output: command output, stdout+stderr combined if split_stderr is disabled, only stdout otherwise - exit_code: exit code of command (integer) - stderr: stderr output if split_stderr is enabled, None otherwise |
run_shell_cmd_cache(func)
¶
Function decorator to cache (and retrieve cached) results of running commands.
subprocess_popen_text(cmd, **kwargs)
¶
Call subprocess.Popen in text mode with specified named arguments.
subprocess_terminate(proc, timeout)
¶
Terminate the subprocess if it hasn't finished after the given timeout