Shivam Pandya
Shivam Pandya

Reputation: 1061

Laravel Artisan: Returns 0 for Python output

I have written one python utility program which returns an array of the result. This utility takes an image path as an input, process that image and in return gives an json array of the result.
Now I want to show this output on my website which is using Laravel 5.7
So I created one artisan command which executes python script and gives me the result.
This command works well in terminal but when I execute this same command from my controller using Artisan::call method, it shows me "0" as the output in the web browser.
I tried shell_exec() too. But the result is the same.

Here is my Artisan Command File

$process = new Process('python3 my_python_script.py -i ' . $this->argument('path'));
$process->run();
$result = $process->getOutput();
return $result;

Artisan Command

php artisan image:upload image_path

Upvotes: 0

Views: 327

Answers (1)

Hilmi Erdem KEREN
Hilmi Erdem KEREN

Reputation: 1999

The call method of Artisan returns integer. It doesn't read from output or it is not your return value from handle method.

See:

/**
 * Run an Artisan console command by name.
 *
 * @param  string  $command
 * @param  array  $parameters
 * @param  \Symfony\Component\Console\Output\OutputInterface|null  $outputBuffer
 * @return int
 */
public function call($command, array $parameters = [], $outputBuffer = null);

Maybe you should try Artisan::output() but I don't think that it is thread safe or something like that.

Upvotes: 0

Related Questions