Script execution error in python in Laravel controller

Asked

Viewed 363 times

3

Currently my scripts work perfectly within Schedule that run at specific times within my server cron.

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

When I make his call by the console or by the Schedule it works correctly, however when I call the method or even a \Artisan::call('schedule:teste'); it returns the same error saying it is not finding the geckdriver.

Imagem com erro sendo chamada pelo Controller

When I run it inside the terminal: it works perfectly: Imagem sem erro dentro do terminal

The Python script is this one: tesouro_directo_precos_taxa_titulo.py

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

From now on I appreciate any and all help.

1 answer

2


Your webserver has different environment variables than your shell. To get an idea of what your environment’s PATH looks like, you can use the function getenv. For example:

echo getenv('path');

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

putenv('path', $path_to_geckodriver);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.