I have to run a bash file through python for a Django webapp project but I cannot retrieve the output of the bash file (which I really need since it needs to be displayed on a web page). here is the code:
in my python file:
import subprocess
output = subprocess.Popen(['bash', 'countingbash.sh', "hello", "world"])
print (output)
in countingbash.sh:
#!/bin/sh
file="$@"
for f in $file
do
echo "Argument is $f"
done
I need to capture the output since it needs to be displayed later on in a webpage. If I run the .py file, the output I get is not what the output should be by running a bash file. The output looks like this:
<subprocess.Popen object at 0x102cab290>
whereas it should be:
Argument is hello
Argument is world
If I run the file alone without writing print(output), the editor shows the output but how do i capture it?