Skip to content

Instantly share code, notes, and snippets.

@WingTillDie
Created July 16, 2023 21:14
Show Gist options
  • Save WingTillDie/da28c8ff1d5809287f171ac5f8a1e54d to your computer and use it in GitHub Desktop.
Save WingTillDie/da28c8ff1d5809287f171ac5f8a1e54d to your computer and use it in GitHub Desktop.
Python wrapper for bash
#!/usr/bin/env python3
import subprocess
import sys
bash_script = '''
echo "$0"
echo "$@"
a=3
<<<$a cat
'''
arguments = sys.argv
def run_bash_script(bash_script, arguments):
command = ['bash', '-c', bash_script] + arguments
p = subprocess.run(command, check=True, capture_output=True, text=True)
stdout = p.stdout
stderr = p.stderr
return stdout, stderr
stdout, stderr = run_bash_script(bash_script, arguments)
print(stdout, end='')
print(stderr, file=sys.stderr, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment