【发布时间】:2015-08-14 19:20:26
【问题描述】:
我有一个 symfony2 控制台组件命令 task:execute,它有一个必需的参数 taskHandle。
protected function configure()
{
parent::configure();
$this
->setName("task:execute")
->setDescription("...")
->addArgument(
'taskHandle',
InputArgument::REQUIRED,
'Which task would you like to run?'
);
...
}
为了做一些批处理工作,我现在想从另一个命令执行这个命令。我不知道应该如何将参数传递给命令。
在我尝试过的 BatchCommand 中:
$command = $this->getApplication()->find('task:execute');
foreach ($handles as $handle) {
$input = new ArgvInput([
'taskHandle', $handle
]);
$command->run($input, $output);
}
或
$command = $this->getApplication()->find('task:execute');
foreach ($handles as $handle) {
$executeInput = new StringInput($handle);
$command->run($executeInput, $output);
}
屈服于:
Invalid taskhandle: does not exist.
我对这个参数被小写感到困惑。然而我的 execute:tasks 在单独调用时工作。从另一个命令传递参数是个问题。
【问题讨论】:
标签: php symfony command-line-arguments