4 ms·
When calling shell from bash (to use pipes etc.), I found it useful to pass variables via the environment, like this: def safe_call(command, **keywds):
by arielb1 6y ago
When calling shell from bash (to use pipes etc.), I found it useful to pass variables via the environment, like this:
def safe_call(command, **keywds):
return subprocess.check_call(f'set -euo pipefail; {command}', shell=True, env=keywds)
safe_call('command1 -- "$bar" | command2 --baz="$baz" | command3 > "$output_file"', bar=bar, baz=baz, output_file=output_file)
- arielb1 6y agoThe main difficulty I have with this method is that I don't have an easy way to pass a Python array to bash as an array of parameters.