简体   繁体   中英

Calling an existing command in symfony2

This is how its supposed to be done according to the documentation

protected function execute(InputInterface $input, OutputInterface $output)
{
    $command = $this->getApplication()->find('demo:greet');

    $arguments = array(
        'command' => 'demo:greet',
        'name'    => 'Fabien',
        '--yell'  => true,
    );

    $greetInput = new ArrayInput($arguments);
    $returnCode = $command->run($greetInput, $output);

    // ...
}

What I want to do is call the command: "php app/console cjw:check-symlinks --vendor=Acme"

but it doesn't work, here's the code:

$command = $this->getApplication()->find('cjw:check-symlinks');

$arguments = array(
    '--vendor'=>'Jac',
);

$Input = new ArrayInput($arguments);
$returnCode = $command->run($Input, $output);

It interrupts the execution and throws the following error:

[RuntimeException] Not enough arguments.

You need to provide all arguments. Command name at least:

$command = $this->getApplication()->find('cjw:check-symlinks');

$arguments = array(
    'command' => 'cjw:check-symlinks',
    // other arguments, depending on cjw:check-symlinks definition 
    '--vendor'=>'Jac',
);

$Input = new ArrayInput($arguments);
$returnCode = $command->run($Input, $output);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM