I'm trying to execute a shell script from python and also capture the output.
I'm using the following lines:
x = subprocess.run(["sh", "/path/to/script/myscript.bash"], stdout=subprocess.PIPE)
print(x.stdout.decode('utf8'))
This works fine when running in python interactive mode, but it just hangs when executed inside a python script and I have to use ctrl+Z to kill the python script. What am I missing?
In the past with python 2.7 I had just used a line like:
x = subprocess.Popen(args='sh /path/to/script/myscript.bash', stdout=subprocess.PIPE, shell=True)
scriptOutput = str(x.communicate()[0])
This doesn't seem to work with python 3.6 which is what I'm running.