I am currently working on a Symfony 6.1 project. I want to execute a Command as a Process from a Controller. However, I do not get it working. Everytime I execute the Command it fails with the Exit Code: (). The Command itself works like a charm if I run it via the cmd.
My current Code for executing the command as a Process:
$cwd = substr(getcwd(), 0, strrpos(getcwd(), '/')).'/';
$process = new Process(['php bin/console example:generate']);
$process->setWorkingDirectory($cwd);
$process->start();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
Other versions I have already tried out:
$process = new Process(['php bin/console example:generate']);
$process->start();
$process = new Process(['php', 'bin/console', 'example:generate']);
$process->start();
$process = new Process(['usr/bin/php', '/var/www/html/bin/console', 'example:generate']);
$process->start();
$process = new Process(['usr/bin/php /var/www/html/bin/console example:generate']);
$process->start();
When I use the dd() Function to show the Process Object, I get the following Informations:
Symfony\Component\Process\Process {#2050
-callback: null
-hasCallback: false
-commandline: array:1 [
0 => "php bin/console example:generate"
]
-cwd: "/var/www/html/"
-env: []
-input: null
-starttime: null
-lastOutputTime: null
-timeout: 60.0
-idleTimeout: null
-exitcode: null
-fallbackStatus: []
-processInformation: null
-outputDisabled: false
-stdout: null
-stderr: null
-process: null
-status: "ready"
-incrementalOutputOffset: 0
-incrementalErrorOutputOffset: 0
-tty: false
-pty: false
-options: array:2 [
"suppress_errors" => true
"bypass_shell" => true
]
-useFileHandles: false
-processPipes: null
-latestSignal: null
}
Can anyone tell me what I am doing wrong here?