execute shell script file in laravel command 1

execute shell script file in laravel command

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();

Here is what the above code is Doing:
1. Create a new Process object and pass the command you want to run as a string.
2. Call the run() method to execute the command.
3. Check if the command was successful by calling the isSuccessful() method.
4. If the command was not successful, throw a ProcessFailedException.
5. Print the output of the command.

Similar Posts