命令未在控制器中执行
Command is not executed in 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'
]);
}
Process 组件将您的命令数组作为构造函数参数。在您的情况下,要调用 php bin/console app:set-info $arg
,您可以这样做:
$process = new Process(['php', 'bin/console', 'app:set-info', $data->info]);
$process->setWorkingDirectory(getcwd() . "/../");
$process->run();
我尝试在控制器函数中使用进程执行命令,它在使用控制台而不是在控制器中执行时有效
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'
]);
}
Process 组件将您的命令数组作为构造函数参数。在您的情况下,要调用 php bin/console app:set-info $arg
,您可以这样做:
$process = new Process(['php', 'bin/console', 'app:set-info', $data->info]);
$process->setWorkingDirectory(getcwd() . "/../");
$process->run();