2 namespace TYPO3\CMS\Core\Utility;
82 public static function exec($command, &$output = null, &$returnValue = 0)
84 $lastLine =
exec($command, $output, $returnValue);
98 $gfxConf =
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'];
99 $isExt = TYPO3_OS ==
'WIN' ?
'.exe' :
'';
100 $switchCompositeParameters =
false;
102 $path = $gfxConf[
'im_path'];
105 $im_version = strtolower($gfxConf[
'im_version_5']);
107 if ($command ===
'combine') {
108 $command =
'composite';
111 if ($im_version ===
'gm') {
112 $switchCompositeParameters =
true;
113 $path = self::escapeShellArgument($path .
'gm' . $isExt) .
' ' . self::escapeShellArgument($command);
115 if ($im_version ===
'im6') {
116 $switchCompositeParameters =
true;
118 $path = self::escapeShellArgument($path . ($command ==
'composite' ?
'composite' : $command) . $isExt);
121 if ($parameters && $command !=
'identify' && $gfxConf[
'im_useStripProfileByDefault'] && $gfxConf[
'im_stripProfileCommand'] !=
'') {
122 if (strpos($parameters, $gfxConf[
'im_stripProfileCommand']) ===
false) {
124 if ($parameters !==
'-version' && strpos($parameters,
'###SkipStripProfile###') ===
false) {
125 $parameters = $gfxConf[
'im_stripProfileCommand'] .
' ' . $parameters;
127 $parameters = str_replace(
'###SkipStripProfile###',
'', $parameters);
131 $cmdLine = $path .
' ' . $parameters;
134 if ($command ==
'composite' && $switchCompositeParameters) {
137 $paramsArrCount = count($paramsArr);
138 if ($paramsArrCount > 5) {
139 $tmp = $paramsArr[$paramsArrCount - 3];
140 $paramsArr[$paramsArrCount - 3] = $paramsArr[$paramsArrCount - 4];
141 $paramsArr[$paramsArrCount - 4] = $tmp;
143 $cmdLine = $path .
' ' . implode(
' ', $paramsArr);
161 if ($handler && !self::checkCommand($handler)) {
165 if (self::$applications[$cmd][
'valid']) {
169 if (isset(self::$applications[$cmd][
'valid'])) {
173 foreach (self::$paths as $path => $validPath) {
176 if (TYPO3_OS ==
'WIN') {
179 if (@is_file($path . $cmd)) {
180 self::$applications[$cmd][
'app'] = $cmd;
181 self::$applications[$cmd][
'path'] = $path;
182 self::$applications[$cmd][
'valid'] =
true;
185 if (@is_file($path . $cmd .
'.exe')) {
186 self::$applications[$cmd][
'app'] = $cmd .
'.exe';
187 self::$applications[$cmd][
'path'] = $path;
188 self::$applications[$cmd][
'valid'] =
true;
193 $filePath = realpath($path . $cmd);
194 if ($filePath && @is_executable($filePath)) {
195 self::$applications[$cmd][
'app'] = $cmd;
196 self::$applications[$cmd][
'path'] = $path;
197 self::$applications[$cmd][
'valid'] =
true;
206 if (TYPO3_OS !=
'WIN') {
207 $cmd = @self::exec(
'which ' . $cmd);
208 if (@is_executable($cmd)) {
209 self::$applications[$cmd][
'app'] = $cmd;
210 self::$applications[$cmd][
'path'] = dirname($cmd) .
'/';
211 self::$applications[$cmd][
'valid'] =
true;
227 public static function getCommand($cmd, $handler =
'', $handlerOpt =
'')
235 $handler = self::getCommand($handler);
240 $handler .=
' ' . $handlerOpt .
' ';
244 if (!self::checkCommand($cmd)) {
247 $cmd = self::$applications[$cmd][
'path'] . self::$applications[$cmd][
'app'] .
' ';
249 return trim($handler . $cmd);
269 public static function getPaths($addInvalid =
false)
278 foreach (
$paths as $path => $validPath) {
292 protected static function init()
294 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'disable_exec_function']) {
297 if (!self::$initialized) {
299 self::$applications = self::getConfiguredApps();
300 self::$initialized =
true;
316 if (!is_array(self::$paths)) {
317 self::$paths = self::getPathsInternal();
324 foreach (
$paths as $path) {
326 if (!preg_match(
'#^/#', $path)) {
327 $path = PATH_site . $path;
329 if (!isset(self::$paths[$path])) {
330 if (@is_dir($path)) {
331 self::$paths[$path] = $path;
333 self::$paths[$path] =
false;
341 foreach (self::$paths as $path => $valid) {
343 if ($valid and !@is_dir($path)) {
344 self::$paths[$path] =
false;
359 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'binSetup']) {
360 $binSetup = str_replace(array(
'\'.chr(10).\
'',
'\' . LF . \
''), LF,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'binSetup']);
361 $pathSetup = preg_split(
'/[\n,]+/', $binSetup);
362 foreach ($pathSetup as $val) {
363 if (trim($val) ===
'') {
367 $cmdArr[$cmd][
'app'] = basename($cmdPath);
368 $cmdArr[$cmd][
'path'] = dirname($cmdPath) .
'/';
369 $cmdArr[$cmd][
'valid'] =
true;
384 $sysPathArr = array();
388 if (($imPath = (
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im_path_lzw'] ?:
$GLOBALS[
'TYPO3_CONF_VARS'][
'GFX'][
'im_path']))) {
389 $imPath = self::fixPath($imPath);
390 $pathsArr[$imPath] = $imPath;
394 if ($GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'binPath']) {
396 foreach ($sysPath as $val) {
397 $val = self::fixPath($val);
398 $sysPathArr[$val] = $val;
404 if ($GLOBALS[
'_SERVER'][
'PATH']) {
405 $sep = (TYPO3_OS ==
'WIN' ?
';' :
':');
407 foreach ($envPath as $val) {
408 $val = self::fixPath($val);
409 $sysPathArr[$val] = $val;
414 if (TYPO3_OS !==
'WIN') {
415 $sysPathArr = array_merge($sysPathArr, array(
416 '/usr/bin/' =>
'/usr/bin/',
417 '/usr/local/bin/' =>
'/usr/local/bin/',
421 $pathsArr = array_merge($pathsArr, $sysPathArr);
434 return str_replace(
'//',
'/', $path .
'/');
447 $isUTF8Filesystem = !empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'UTF8filesystem']);
448 if ($isUTF8Filesystem) {
449 $currentLocale = setlocale(LC_CTYPE, 0);
450 setlocale(LC_CTYPE,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLocale']);
453 $output = array_map(
'escapeshellarg', $input);
455 if ($isUTF8Filesystem) {
456 setlocale(LC_CTYPE, $currentLocale);
472 return self::escapeShellArguments(array($input))[0];