Reputation:
How run a command as command line from a symfony function?
E.g.
C:\SymfonyProject> php app/console my-command --option=my-option
I want to run this command from a function. This command export files from a database and place this files in app/Resource/translations folder from Symfony Project.
I.e.
public function exportFiles(){ // I want to run command here. }
Thanks! :)
Upvotes: 1
Views: 4109
Reputation: 2295
You could use the Symfony Process component for that. The code would look something like this:
private function process(OutputInterface $output)
{
$cmd = 'php app/console my-command --option=my-option';
$process = new Process($cmd);
$process->setTimeout(60);
$process->run(
function ($type, $buffer) use ($output) {
$output->write((Process::ERR === $type) ? 'ERR:' . $buffer : $buffer);
}
);
Upvotes: 2