2

i faced a problem when upgrade from 2.1 to 2.2

in my action controller i am calling a console command and get the output from the command like this.

$input = new ArgvInput(array(
                                'object_id' => $object_id,
                                'client_id' => $client_id,
                                'email_address' => $email
                                )
                           );

    $output = new ConsoleOutput();

    $command = $this->get('mycommand');
    $returnCode = $command->run($input, $output);

    $response = stream_get_contents($output->getStream());

it worked in symfony 2.1, but after upgrading to 2.2 first i got the following exception "Not enough arguments.". To prevent this i have added a dummy parameter in front of others.

But after this the command executes, but i cant read the output, it always empty.

Is there any solution for this?

2 Answers 2

4

The Symfony 2.4 branch added a BufferedOutput which does exactly what you want.

    $input = new ArgvInput(array());
    $output = new BufferedOutput();

    $command = $this->get("command");
    $command->run($input, $output);

    $content = $output->fetch();
Sign up to request clarification or add additional context in comments.

Comments

2

I found the following gist which replaces the ConsoleOutput with the following MemoryWriter class to solve the problem.

It also suggests using the Symfony\Bundle\FrameworkBundle\Console\Application class to avoid having to create the command as a service:

$application = new Application($this->getContainer()->get('kernel'));
$application->setAutoExit(false); 

// The input interface should contain the command name, and whatever arguments the command needs to run      
$input = new ArrayInput(array("doctrine:schema:update"));

// Run the command
$retval = $application->run($input, $output);

var_dump($output->getOutput());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.