Hacker News new | ask | show | jobs
by arielb1 1909 days 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)
1 comments

The 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.