0

I've got my website hosted at one.com and I'd like to run a simple python script with php that returns 'hello' but I get no result. It worked perfectly on local with Mamp. What should I configure for it to work online ?

My php code:

<?php
$result = shell_exec('python test.py');
echo $result;
 ?>

The python script

print('hello')

2
  • have you got #!/usr/bin/env python or your path to python at the top of the file to make it executable. Also check that the python file has 755 permissions Commented Nov 21, 2017 at 22:17
  • It's probably disabled stackoverflow.com/questions/21581560/… Commented Nov 21, 2017 at 22:21

1 Answer 1

1

First of all make sure that the python script is executable on the server. For safety reasons I would remove the space in the filename as well so make it just test.py for now. You can make it executable by simple changing the permissions using chmod +x test.py

Then, you can try the following lines of code in php

<?php 

$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.