How can I run a command (app/console execute:my:command) in a service via new Process?
I try this:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process(
'app/console execute:my:command'
);
$process->start();
But nothing happens ... If I call it manually via terminal it works:
app/console execute:my:command
What am I doing wrong?
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);
}