I get an Exec format error when trying to run a Python script in PHP. Why?Get the solution ↓↓↓
I am trying to run a Python script within PHP and I have been troubleshooting this for about a day or more, and I checked my error log and figured out the exact error. This is the error:
sh: 1: 3.8/bin/python3: Exec format error
Why am I getting this error? This is my code along with the exec:
<?php $command = '3.8/bin/python3 googleNewsScraper.py CNN'; $output = shell_exec($command); echo $status; echo $output; ?>
I have tried
json_decode which should help. I am wondering if printing the output from the function I am running in python:
Question: Does this work for the output? When I do json_decode that does nothing, but when I do json_encode it just returns null, and when I echo it without anything, just the variable, it doesnt put anything on the page. Why could this happen? When I run it on the command line with
php index.php the entirety of the json object is echo'd to the command line.
Edit: The error has changed and no longer includes all the stuff
People are also looking for solutions of the problem: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.