如何通过 new Process 在服务中运行命令 (app/console execute:my:command)?
我尝试了以下代码:
我做错了什么?
我尝试了以下代码:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process(
'app/console execute:my:command'
);
$process->start();
但是什么都没有发生... 如果我通过终端手动调用它,它就可以工作:
app/console execute:my:command
我做错了什么?
EDIT - Solution: We need to write the whole path. In my case:
($this->kernelRootDir is : %kernel.root_dir%)
$processString = sprintf(
'php %s/../app/console %s %s',
$this->kernelRootDir,
self::MY_COMMAND,
$myArgument
);
$process = new Process($processString);
$process->start();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}