Run .sh file using exec Laravel PHP

后端 未结 3 1870
灰色年华
灰色年华 2021-01-14 20:15

I am trying to run a .sh file that will import a excel file to my database. Both files are in same directory inside the public folder. For some reason the exec command isn\'

3条回答
  •  孤街浪徒
    2021-01-14 20:51

    you can use Process Component of Symfony that is already in Laravel http://symfony.com/doc/current/components/process.html

    use Symfony\Component\Process\Process;
    use Symfony\Component\Process\Exception\ProcessFailedException;
    
    $process = new Process('sh /folder_name/file_name.sh');
    $process->run();
    
    // executes after the command finishes
    if (!$process->isSuccessful()) {
        throw new ProcessFailedException($process);
    }
    
    echo $process->getOutput();
    

提交回复
热议问题