You are here

public function ImagemagickExecManager::runOsShell in ImageMagick 8.2

Same name and namespace in other branches
  1. 8.3 src/ImagemagickExecManager.php \Drupal\imagemagick\ImagemagickExecManager::runOsShell()

Executes a command on the operating system.

This differs from ::runOsCommand in the sense that here the command to be executed and its arguments are passed separately.

Parameters

string $command: The command to run.

string $arguments: The arguments of the command to run.

string $id: An identifier for the process to be spawned on the operating system.

string &$output: (optional) A variable to assign the shell stdout to, passed by reference.

string &$error: (optional) A variable to assign the shell stderr to, passed by reference.

Return value

int|bool The operating system returned code, or FALSE if it was not possible to execute the command.

Overrides ImagemagickExecManagerInterface::runOsShell

3 calls to ImagemagickExecManager::runOsShell()
ImagemagickExecManager::checkPath in src/ImagemagickExecManager.php
Verifies file path of the executable binary by checking its version.
ImagemagickExecManager::execute in src/ImagemagickExecManager.php
Executes the convert executable as shell command.
ImagemagickExecManager::getInstalledLocales in src/ImagemagickExecManager.php
Gets the list of locales installed on the server.

File

src/ImagemagickExecManager.php, line 370

Class

ImagemagickExecManager
Manage execution of ImageMagick/GraphicsMagick commands.

Namespace

Drupal\imagemagick

Code

public function runOsShell($command, $arguments, $id, &$output = NULL, &$error = NULL) {
  $command_line = $command . ' ' . $arguments;
  $output = '';
  $error = '';
  Timer::start('imagemagick:runOsShell');
  $process = new Process($command_line, $this->appRoot);
  $process
    ->setTimeout($this->timeout);
  try {
    $process
      ->run();
    $output = utf8_encode($process
      ->getOutput());
    $error = utf8_encode($process
      ->getErrorOutput());
    $return_code = $process
      ->getExitCode();
  } catch (\Exception $e) {
    $error = $e
      ->getMessage();
    $return_code = $process
      ->getExitCode() ? $process
      ->getExitCode() : 1;
  }
  $execution_time = Timer::stop('imagemagick:runOsShell')['time'];

  // Process debugging information if required.
  if ($this->configFactory
    ->get('imagemagick.settings')
    ->get('debug')) {
    $this
      ->debugMessage('@suite command: <pre>@raw</pre> executed in @execution_timems', [
      '@suite' => $this
        ->getPackageLabel($id),
      '@raw' => print_r($command_line, TRUE),
      '@execution_time' => $execution_time,
    ]);
    if ($output !== '') {
      $this
        ->debugMessage('@suite output: <pre>@raw</pre>', [
        '@suite' => $this
          ->getPackageLabel($id),
        '@raw' => print_r($output, TRUE),
      ]);
    }
    if ($error !== '') {
      $this
        ->debugMessage('@suite error @return_code: <pre>@raw</pre>', [
        '@suite' => $this
          ->getPackageLabel($id),
        '@return_code' => $return_code,
        '@raw' => print_r($error, TRUE),
      ]);
    }
  }
  return $return_code;
}