EchoLogic EchoLogic - 5 months ago 45
Python Question

How to run python script with Laravel's command fire method?

I have a need to execute a Python script from a Laravel Command, but I can't find any methods in

Illuminate\Console\Command
to complete my task.

I want to run this command via the console:

C:\Python34\python H:\myapp\app\python\questionPopulator.py


To do so, I tried the following in my commands
fire()
method:

public function fire()
{
$this->call('C:\Python34\python H:\myapp\app\python\questionPopulator.py');
}


public function fire()
{
$this->line('C:\Python34\python H:\myapp\app\python\questionPopulator.py');
}


None of them work, as Laravel is expecting me to be calling another Laravel command from them. What is the best way to call a simple python script via a Laravel Command?

Answer

try PHP exec function: http://php.net/manual/en/function.exec.php

exec('C:\Python34\python H:\myapp\app\python\questionPopulator.py');