Printing PHP errors with python
<p>I'm using the following to run PHP code with python. If the PHP code located in the file.php encounters an error, I can see the error on my terminal, but I want to have the error on the result variable.</p>

<p>How can I catch the error as a string?</p>

<pre><code>proc = subprocess.Popen("php /path/file.php", shell=True, stdout=subprocess.PIPE)
result = proc.stdout.read().decode("utf-8")
</code></pre>

<p>The error messages are usually written to <code>stderr</code>, rather than <code>stdout</code>. If that is the case, you can get it from the corresponding attribute.</p>

<pre><code>proc = subprocess.Popen(["php", "/path/file.php"],
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = proc.stdout.read().decode("utf-8")
err = proc.stderr.read().decode("utf-8")
</code></pre>

php python