Home > Software design >  Command is not executed in controller
Command is not executed in controller

Time:05-31

I try to execute a command using a Process in a controller function, its works when is executed using the console but not in the controller

public function addInfo(Request $request):JsonResponse{
        $data = json_decode($request->getContent());
        
        try{
            $process = new Process(['php ../bin/console app:set-info '.$data->info]);
            $process->start();

        }catch(Throwable $e){
            echo $e->getMessage();
        }

        return new JsonResponse([
            'state'=>'succes'
         ]);
    }

CodePudding user response:

The Process component takes an array of your commands as a constructor argument. In your case, to call php bin/console app:set-info $arg, you would do this:

$process = new Process(['php', 'bin/console', 'app:set-info', $data->info]);
$process->setWorkingDirectory(getcwd() . "/../");
$process->run();
  • Related