Created
July 16, 2023 21:14
-
-
Save WingTillDie/da28c8ff1d5809287f171ac5f8a1e54d to your computer and use it in GitHub Desktop.
Python wrapper for bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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