setTimeout($timeout); $process->mustRun(); $output = $process->getOutput(); if (static::isValidOutput($output)) { return true; } } catch (Exception | InvalidArgumentException | LogicException | ProcessFailedException | RuntimeException | Throwable $e) { $output = $e->getMessage(); } logger('Console output:: ' . $output); return static::formatOutput($output); } public static function formatOutput($output) { $output = nl2br($output); $output = str_replace(['"', "'"], '', $output); $output = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $output); return $output; } public static function isValidOutput($output) { $errors = [ 'Content-Type: application/json', 'CSRF token mismatch', ]; return !Str::contains($output, $errors); } }