1

I was trying to execute a basic python script (print "hello world") via PHP . I saw numerous such question of SO which helped me make a php script to run the program which looks like this:

<?php
$result = exec('python phptry.py');
echo $result;
?>

where phptry.py is the name of the hello world program. However the php page doesnt return anything (blank / white page) . Are any additional plug-ins required?

Also, my actual aim is to run a much larger python script which has a list of tuples ( which i unpack and print via python as of now) which i wanna display on the php page

0

1 Answer 1

1

You may want to try using shell_exec() instead as exec(). You could also try to use system()

Possible duplicate of: Running a Python script on a PHP server

Sign up to request clarification or add additional context in comments.

5 Comments

I dint find that one. Thanks a lot
No problem, hope that helps!
ok i did try using the shell_exec() but , i still dont get any result. Is it because i wrote the python script in pyhton 2.7.x , but i have multiple python versions in my computer
EUREKA!! <?php echo shell_exec('phptry.py'); ?> works. Got rid of python before the python script name
Glad you got it working!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.