So, I am trying to run a python script in my Laravel 5.3.
This function is inside my Controller. This simply passes data to my python script
public
Use Symfony Process. https://symfony.com/doc/current/components/process.html
Install:
composer require symfony/process
Code:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process(['python', '/path/to/your_script.py']);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();