diff --git a/typo3/sysext/core/Classes/Utility/CommandUtility.php b/typo3/sysext/core/Classes/Utility/CommandUtility.php
index bb89725040877bea8339ff13ea26de63b6c15f4c..fee329decc28955a1b6c5cff3c867cbe3518e886 100644
--- a/typo3/sysext/core/Classes/Utility/CommandUtility.php
+++ b/typo3/sysext/core/Classes/Utility/CommandUtility.php
@@ -213,8 +213,11 @@ class CommandUtility
         // Try to get the executable with the command 'which'.
         // It does the same like already done, but maybe on other paths
         if (!Environment::isWindows()) {
-            $cmd = @self::exec('which ' . self::escapeShellArgument($cmd));
-            if (@is_executable($cmd)) {
+            $output = null;
+            $returnValue = 0;
+            $cmd = @self::exec('which ' . self::escapeShellArgument($cmd), $output, $returnValue);
+
+            if ($returnValue === 0) {
                 self::$applications[$cmd]['app'] = $cmd;
                 self::$applications[$cmd]['path'] = PathUtility::dirname($cmd) . '/';
                 self::$applications[$cmd]['valid'] = true;
diff --git a/typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php b/typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php
index b1bc93ae034a5c12551f1c4c60b7e24c8b26c7c6..c060d4c9e105d5733670b10e90d34e1c0c9e2813 100644
--- a/typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php
+++ b/typo3/sysext/install/Classes/Configuration/Image/GraphicsMagickPreset.php
@@ -72,19 +72,19 @@ class GraphicsMagickPreset extends AbstractImagePreset
             } else {
                 $executable = 'gm';
             }
-            if (@is_file($path . $executable)) {
-                $command = escapeshellarg($path . $executable) . ' -version';
-                $executingResult = [];
-                CommandUtility::exec($command, $executingResult);
-                // First line of exec command should contain string GraphicsMagick
-                $firstResultLine = array_shift($executingResult);
-                if (str_contains($firstResultLine, 'GraphicsMagick')) {
-                    $this->foundPath = $path;
-                    $result = true;
-                    break;
-                }
+
+            $command = escapeshellarg($path . $executable) . ' -version';
+            $executingResult = [];
+            @CommandUtility::exec($command, $executingResult);
+            // First line of exec command should contain string GraphicsMagick
+            $firstResultLine = (string)array_shift($executingResult);
+            if (str_contains($firstResultLine, 'GraphicsMagick')) {
+                $this->foundPath = $path;
+                $result = true;
+                break;
             }
         }
+
         return $result;
     }
 }
diff --git a/typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php b/typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php
index fb5b51977f31733c727c193186d73e53e4ec7312..3e7e3a1fe602a061465afd29f3e74c8b55e419e3 100644
--- a/typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php
+++ b/typo3/sysext/install/Classes/Configuration/Image/ImageMagick6Preset.php
@@ -76,22 +76,20 @@ class ImageMagick6Preset extends AbstractImagePreset
             } else {
                 $executable = 'identify';
             }
-            if (@is_file($path . $executable)) {
-                $command = escapeshellarg($path . $executable) . ' -version';
-                $executingResult = [];
-                CommandUtility::exec($command, $executingResult);
-                // First line of exec command should contain string GraphicsMagick
-                $firstResultLine = array_shift($executingResult);
-                // Example: "Version: ImageMagick 6.6.0-4 2012-05-02 Q16 http://www.imagemagick.org"
-                if (str_contains($firstResultLine, 'ImageMagick')) {
-                    [, $version] = explode('ImageMagick', $firstResultLine);
-                    // Example: "6.6.0-4"
-                    [$version] = explode(' ', trim($version));
-                    if (version_compare($version, '6.0.0') >= 0) {
-                        $this->foundPath = $path;
-                        $result = true;
-                        break;
-                    }
+            $command = escapeshellarg($path . $executable) . ' -version';
+            $executingResult = [];
+            CommandUtility::exec($command, $executingResult);
+            // First line of exec command should contain string GraphicsMagick
+            $firstResultLine = array_shift($executingResult);
+            // Example: "Version: ImageMagick 6.6.0-4 2012-05-02 Q16 http://www.imagemagick.org"
+            if (str_contains($firstResultLine, 'ImageMagick')) {
+                [, $version] = explode('ImageMagick', $firstResultLine);
+                // Example: "6.6.0-4"
+                [$version] = explode(' ', trim($version));
+                if (version_compare($version, '6.0.0') >= 0) {
+                    $this->foundPath = $path;
+                    $result = true;
+                    break;
                 }
             }
         }