Skip to content
Advertisement

Calling console command within command and get the output in Symfony2

I have a few console command in Symfony2 and I need to execute one command from another command with some parameters.

After successfull execution of the second command I need to get the result (as an array for example), not the display output.

How can I do that?

Advertisement

Answer

Here you can have a basic command inside a command. The output from the second command can be a json, then you just have to decode the output json to retrieve your array.

$command = $this->getApplication()->find('doctrine:fixtures:load');
$arguments = array(
    //'--force' => true
    ''
);
$input = new ArrayInput($arguments);
$returnCode = $command->run($input, $output);

if($returnCode != 0) {
    $text .= 'fixtures successfully loaded ...';
    $output = json_decode(rtrim($output));
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement