Im trying to execute a bash script through python, capture the output of the bash script and use it in my python code. Im using subprocess.run(), however, my output comes empty. Can you spot a mistake in my code?
- when trying to forward the output to a file I can see the output currectly
Here is my python code - example.py (I'm using Python 3.8.5):
import os, subprocess
res = subprocess.run(os.path.join('T:', 'myfolder', 'input-script.sh'), shell=True, capture_output=True, text=True)
print(res)
Here is my bash script - input-script.sh:
#!/bin/sh
read -p "enter input:" reply
echo "output: $reply"
Bash input: "hello world"
Python output:
CompletedProcess(args='T:myfolder\\input-script.sh', returncode=0, stdout='', stderr='')
Expected Python output:
CompletedProcess(args='T:myfolder\\input-script.sh', returncode=0, stdout='hello world', stderr='')