title: How to execute python script from php?
body: <p>I'm new to <code>php</code> and <code>html</code> (internet languages in general) and I would like to execute a <code>python</code> script that takes a picture from my php page.</p>
  
  <p>I did some research, edited some code (according to my understanding) and came up with this, but it doens't do anything.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
          &lt;title&gt;Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;form action="" method="post"&gt;
                  &lt;button type="submit" name="sub" value="call"&gt;Click&lt;/button&gt;
          &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php
  if(isset($_POST['sub']))
  {
          exec('sudo python take_picture.py');
          echo "Picture captured";
  }
  ?&gt;
  </code></pre>
  
  <p>I managed to execute the <code>python</code> script from a <code>html</code> page invoking a simple <code>php</code> script separately, but when it takes the picture it sends me to a new page (blank page with the text displayed) which I don't want. Here are the codes:</p>
  
  <p>HTML button:</p>
  
  <pre><code>&lt;form action="take_picture.php" method="post"&gt;
  &lt;button&gt;Click&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP script:</p>
  
  <pre><code>&lt;?php
  exec('sudo python take_picture.py');
  ?&gt;
  </code></pre>
  
  <p>What I need is to simply press the "click" button and take the picture without sending me to anywhere else.</p>
  
  <p>Could you please guys aid me to achieve what I need and explain with apples what I was doing wrong or what I missed.</p>
  
  <p>Thank you in advance!</p>