2019-12-03 12:41:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Utilities;
|
|
|
|
|
|
2020-06-28 06:39:20 +00:00
|
|
|
use Illuminate\Console\Application;
|
2019-12-03 12:41:56 +00:00
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
|
|
|
|
|
|
class Console
|
|
|
|
|
{
|
2020-03-19 14:18:19 +00:00
|
|
|
public static function run($string, $all_output = false, $timeout = 0)
|
2019-12-03 12:41:56 +00:00
|
|
|
{
|
2020-06-28 06:39:20 +00:00
|
|
|
$command = Application::formatCommandString($string);
|
2020-03-19 14:18:19 +00:00
|
|
|
|
2020-05-19 23:20:48 +00:00
|
|
|
logger('Console command:: ' . $command);
|
|
|
|
|
|
2020-03-16 16:35:58 +00:00
|
|
|
$process = Process::fromShellCommandline($command, base_path());
|
2020-02-05 07:24:18 +00:00
|
|
|
$process->setTimeout($timeout);
|
2019-12-03 12:41:56 +00:00
|
|
|
|
|
|
|
|
$process->run();
|
|
|
|
|
|
|
|
|
|
if ($process->isSuccessful()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 14:34:24 +00:00
|
|
|
$output = $all_output ? $process->getOutput() : $process->getErrorOutput();
|
|
|
|
|
|
2020-05-19 23:20:48 +00:00
|
|
|
logger('Console output:: ' . $output);
|
2020-03-19 14:34:24 +00:00
|
|
|
|
|
|
|
|
return $output;
|
2019-12-03 12:41:56 +00:00
|
|
|
}
|
|
|
|
|
}
|