Have you tried returning the $output?
public function handle()
{
$exec_string = 'node public/js/generateBudgetDates.js';
exec($exec_string, $output);
return $output;
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to call Artisan command from one of my controllers like explained here: http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli but how could I get commands output?
Inside my command I can get output for example with exec
public function handle()
{
$exec_string = 'node public/js/generateBudgetDates.js';
exec($exec_string, $output);
dump($output);
}
but this approach does not give me result when i run similar command from inside controller... $output is left empty then.
So again - question is how could I get data returned by generateBudgetDates.js data from command to my laravel code?
@janareit use proc_open to get both stderr and stdout :
// Setup the file descriptors
$descriptors = [
0 => ['pipe', 'w'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
// Start the script
$proc = proc_open($cmd, $descriptors, $pipes);
// Read the stdin
$stdin = stream_get_contents($pipes[0]);
fclose($pipes[0]);
// Read the stdout
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// Read the stderr
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
// Close the script and get the return code
$return_code = proc_close($proc);
Please or to participate in this conversation.