I'm trying to run a python script from laravel. I'm using the version 5.6
.
In a controller I have this
public function test_python()
{
$command = escapeshellcmd('python ' . public_path() . '\test\test.py');
$output = shell_exec($command);
dd($output);
}
But it return me null
.
The output should be Hello World!
test.py
#!/usr/bin/env python
print('Hello World!')
If a create a php file outside my laravel folder with this
<?php
$command = escapeshellcmd('python C:\wamp64\www\projects\laravel\public\test\test.py');
$output = shell_exec($command);
echo $output;
And when I run php path/outside/laravel/test.php
from the command line, I see the correct result.
The test.py
have the right permission (-rwxr-xr-x
). And python is also correct regarding the environnement path.
I also tried to use the full path of the script, but is still failing.
PS: The answer from this post are not working for me