public static function executeCommand(string $commandIdentifier, array $settings, bool $outputResults = true, array $commandArguments = []): bool
    {
        $command = self::buildSubprocessCommand($commandIdentifier, $settings, $commandArguments);
        $output = [];
        // Output errors in response
        $command .= ' 2>&1';
        exec($command, $output, $result);
        if ($result !== 0) {
            if (count($output) > 0) {
                $exceptionMessage = implode(PHP_EOL, $output);
            } else {
                $exceptionMessage = sprintf('Execution of subprocess failed with exit code %d without any further output. (Please check your PHP error log for possible Fatal errors)', $result);

                // If the command is too long, it'll just produce /usr/bin/php: Argument list too long but this will be invisible
                // If anything else goes wrong, it may as well not produce any $output, but might do so when run on an interactive
                // shell. Thus we dump the command next to the exception dumps.
                $exceptionMessage .= ' Try to run the command manually, to hopefully get some hint on the actual error.';

                if (!file_exists(FLOW_PATH_DATA . 'Logs/Exceptions')) {
                    Files::createDirectoryRecursively(FLOW_PATH_DATA . 'Logs/Exceptions');
                }
                if (file_exists(FLOW_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW_PATH_DATA . 'Logs/Exceptions')) {
                    $referenceCode = date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
                    $errorDumpPathAndFilename = FLOW_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '-command.txt';
                    file_put_contents($errorDumpPathAndFilename, $command);
                    $exceptionMessage .= sprintf(' It has been stored in: %s', basename($errorDumpPathAndFilename));
                } else {
                    $exceptionMessage .= sprintf(' (could not write command into %s because the directory could not be created or is not writable.)', FLOW_PATH_DATA . 'Logs/Exceptions/');
                }
            }
            throw new Exception\SubProcessException($exceptionMessage, 1355480641);
        }
        if ($outputResults) {
            echo implode(PHP_EOL, $output);
        }
        return $result === 0;
    }
public static function executeCommand(string $commandIdentifier, array $settings, bool $outputResults = true, array $commandArguments = []): bool
    {
        $command = self::buildSubprocessCommand($commandIdentifier, $settings, $commandArguments);
        $output = [];
        // Output errors in response
        $command .= ' 2>&1';
        exec($command, $output, $result);
        if ($result !== 0) {
            if (count($output) > 0) {
                $exceptionMessage = implode(PHP_EOL, $output);
            } else {
                $exceptionMessage = sprintf('Execution of subprocess failed with exit code %d without any further output. (Please check your PHP error log for possible Fatal errors)', $result);

                // If the command is too long, it'll just produce /usr/bin/php: Argument list too long but this will be invisible
                // If anything else goes wrong, it may as well not produce any $output, but might do so when run on an interactive
                // shell. Thus we dump the command next to the exception dumps.
                $exceptionMessage .= ' Try to run the command manually, to hopefully get some hint on the actual error.';

                if (!file_exists(FLOW_PATH_DATA . 'Logs/Exceptions')) {
                    Files::createDirectoryRecursively(FLOW_PATH_DATA . 'Logs/Exceptions');
                }
                if (file_exists(FLOW_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW_PATH_DATA . 'Logs/Exceptions')) {
                    $referenceCode = date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
                    $errorDumpPathAndFilename = FLOW_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '-command.txt';
                    file_put_contents($errorDumpPathAndFilename, $command);
                    $exceptionMessage .= sprintf(' It has been stored in: %s', basename($errorDumpPathAndFilename));
                } else {
                    $exceptionMessage .= sprintf(' (could not write command into %s because the directory could not be created or is not writable.)', FLOW_PATH_DATA . 'Logs/Exceptions/');
                }
            }
            throw new Exception\SubProcessException($exceptionMessage, 1355480641);
        }
        if ($outputResults) {
            echo implode(PHP_EOL, $output);
        }
        return $result === 0;
    }
public static function executeCommand ( string $ commandIdentifier , array $ settings , bool $ outputResults = true , array $ commandArguments = [ ] ) : bool { $ command = self :: buildSubprocessCommand ( $ commandIdentifier , $ settings , $ commandArguments ) ; $ output = [ ] ; // Output errors in response $ command .= ' 2>&1' ; exec ( $ command , $ output , $ result ) ; if ( $ result !== 0 ) { if ( count ( $ output ) > 0 ) { $ exceptionMessage = implode ( PHP_EOL , $ output ) ; } else { $ exceptionMessage = sprintf ( 'Execution of subprocess failed with exit code %d without any further output. (Please check your PHP error log for possible Fatal errors)' , $ result ) ; // If the command is too long, it'll just produce /usr/bin/php: Argument list too long but this will be invisible // If anything else goes wrong, it may as well not produce any $output, but might do so when run on an interactive // shell. Thus we dump the command next to the exception dumps. $ exceptionMessage .= ' Try to run the command manually, to hopefully get some hint on the actual error.' ; if ( ! file_exists ( FLOW_PATH_DATA . 'Logs/Exceptions' ) ) { Files :: createDirectoryRecursively ( FLOW_PATH_DATA . 'Logs/Exceptions' ) ; } if ( file_exists ( FLOW_PATH_DATA . 'Logs/Exceptions' ) && is_dir ( FLOW_PATH_DATA . 'Logs/Exceptions' ) && is_writable ( FLOW_PATH_DATA . 'Logs/Exceptions' ) ) { $ referenceCode = date ( 'YmdHis' , $ _SERVER [ 'REQUEST_TIME' ] ) . substr ( md5 ( rand ( ) ) , 0 , 6 ) ; $ errorDumpPathAndFilename = FLOW_PATH_DATA . 'Logs/Exceptions/' . $ referenceCode . '-command.txt' ; file_put_contents ( $ errorDumpPathAndFilename , $ command ) ; $ exceptionMessage .= sprintf ( ' It has been stored in: %s' , basename ( $ errorDumpPathAndFilename ) ) ; } else { $ exceptionMessage .= sprintf ( ' (could not write command into %s because the directory could not be created or is not writable.)' , FLOW_PATH_DATA . 'Logs/Exceptions/' ) ; } } throw new Exception \ SubProcessException ( $ exceptionMessage , 1355480641 ) ; } if ( $ outputResults ) { echo implode ( PHP_EOL , $ output ) ; } return $ result === 0 ; }
Executes the given command as a sub-request to the Flow CLI system.

@param string $commandIdentifier E.g. neos.flow:cache:flush
@param array $settings The Neos.Flow settings
@param boolean $outputResults if false the output of this command is only echoed if the execution was not successful
@param array $commandArguments Command arguments
@return boolean true if the command execution was successful (exit code = 0)
@api
@throws Exception\SubProcessException if execution of the sub process failed
Executes the given command as a sub - request to the Flow CLI system .