title: How to execute Shell Script from Flask App
body: <p>I've created and deployed a Flask App with Apache2 server WSGI in which now would like to run a .sh script from the App.  However, from calling from python code, it doesn't execute. </p>
  
  <p>Here is the test.sh:</p>
  
  <pre><code>#!/bin/bash
  echo "hi from shell script"
  </code></pre>
  
  <p>Here is my python flask app code index.py (runs when App is opened) but nothing is printed or executed:</p>
  
  <pre><code>import subprocess
  subprocess.call('/var/www/FlaskApp/FlaskApp/scripts/test.sh')
  </code></pre>
  
  <p>To check that there is not errors in my code, I've check flask error logs, and no errors.  Also, I created a script called test_shell_script.py with same python code as above (but not flask app code) and it runs great like this:</p>
  
  <pre><code># test_shell_script.py
  import subprocess
  subprocess.call('/var/www/FlaskApp/FlaskApp/scripts/test.sh')
  </code></pre>
  
  <p>And then run it with python:
      python3 /var/www/FlaskApp/FlaskApp/test_shell_script.py</p>
  
  <pre><code>hi from shell script
  </code></pre>
  
  <p>I did change the permissions as well:</p>
  
  <pre><code>-rwxr-xr-x 1 root root 364 Nov 19 17:48 ../scripts/test.sh
  </code></pre>
  
  <p>What am I missing here which is not allowing my Flask app to run shell commands from the python code?</p>