0

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

1 Answer 1

0

For first, maybe "php user" dont have permission for running? I meen php dont see global path variable.

Also, you can use library for it Symfony\Proccess

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.