EmbeddedServer::_runScript PHP Method

_runScript() public method

Run the given script.
public _runScript ( $script, $log = true, $parameters = '' ) : boolean
$script string The script to be executed (without platform specific extension).
$log boolean Whether to log the script execution. Logging is NOT supported on Windows due to locking issues with the log file when being started through 'start /b'.
$parameters string Optional script parameters.
return boolean true if the command executed successfully, otherwise false.
    function _runScript($script, $log = true, $parameters = '')
    {
        // Assemble the shell command.
        $command = $this->_getScriptPath($script);
        if (!empty($parameters)) {
            $command .= ' ' . $parameters;
        }
        // Long running background processes cause
        // locking issues on Windows.
        $allowLock = true;
        if (Core::isWindows() && $script === 'start') {
            $allowLock = false;
        }
        // Configure logging (not supported on Windows
        // due to locking issues).
        if ($allowLock && $log) {
            $logFile = $this->_getLogFileName();
            $command .= " 2>&1 >>\"{$logFile}\"";
        } else {
            if (Core::isWindows()) {
                $command .= ' 2>&1 >NUL';
            } else {
                $command .= ' 2>&1 >/dev/null';
            }
        }
        if (Core::isWindows()) {
            $command .= ' <NUL';
        } else {
            $command .= ' </dev/null';
        }
        // Execute the command.
        if ($allowLock) {
            exec($command, $dummy, $returnStatus);
        } else {
            // Do not lock up PHP on Windows.
            pclose(popen($command, 'r'));
            $returnStatus = 0;
        }
        // Return the result.
        return $returnStatus === 0;
    }