Error executing script in python in Laravel controller

3

Currently my scripts work perfectly within the schedule that run at specific times within my server's cron.

The problem is occurring when I try to execute the method inside the controller, this method basically uses a shell_exec () that executes a script in python and this return is what I deal with Laravel.

When I call it from the console or the schedule it works correctly, but when I call the method or even a \Artisan::call('schedule:teste'); it returns the same error saying that it is not encountering the geckdriver.

WhenIrunitinsidetheterminal:itworksperfectly:

ThescriptinPythonisthisone: treasure_direto_precos_taxa_tipulo.py

From what I'm noticing when I run the command inside the controller, it is not using the path of my system. The question is why?

From now on I thank you for all your help.

    
asked by anonymous 29.06.2018 / 22:36

1 answer

2

Your webserver has different environment variables than your shell. To get an idea of how the PATH of your environment is, you can use the getenv function. For example:

echo getenv('path');

To solve your problem, simply use the putenv function by setting the PATH to the geckodriver path before calling the script.

putenv('path', $path_to_geckodriver);
    
10.07.2018 / 02:15