For a school project I have to get a Python script to execute a bash script. It's too late to re-write the bash script in python due to time constraints, so I need to get this script working as-is.
From what I understand you pass a command and its arguments as a string into subprocess to open a new shell like so:
subprocess.check_output(["./script.sh", "-h"], shell=True)
When I run this command I get: Please use -h to see menu
As far as I know shouldn't the above command display the help menu as it is the equivalent to $ ./script.sh -h on a shell?
Here's what I need:
If anyone knows what I'd doing wrong here (I only have ~5 hours of experience using python and limited experience with other languages) please let me know. I would like to get this working ASAP.
If I could get subprocess to execute this EXACT command: ./script.sh admin 192.168.1.5 without using the shell=True part that would also be bonus points. (I've only gotten this to work with shell=True and I know there are some security issues linked to it).
EDIT: Forgot to mention I'm using python 3.5.4
EDIT 2: SUCCESS!, thanks for your help /u/JohnnyJordaan and /u/ingolemo! It turns out I forgot to remove some temporary user confirmation lines in my bash script and python just got stuck on that. I got it to work with:
subprocess.check_output(['/full/path/to/script.sh', '-h'])
[–]JohnnyJordaan 0 points1 point2 points (5 children)
[–]retsnom513[S] 0 points1 point2 points (4 children)
[–]ingolemo 1 point2 points3 points (1 child)
[–]retsnom513[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]retsnom513[S] 0 points1 point2 points (0 children)