执行一段脚本
@param string $script 脚本
@param array $keys 键(可在脚本中使用KEYS[1],KEYS[2]访问 ,从1开始
@param array $argv 参数(可在脚本中使用ARGV[1],ARGV[2]访问 ,从1开始
@return mixed
489200
public function exec(string $script, array $keys = [], array $argv = [])
    {
        return $this->handle->eval($script, array_merge($keys, $argv), count($keys));
    }
1243388
public function trans(string $key, array $args = [], $lang = '')
    {
        return $this->translate($key, $args, $lang);
    }
1262543
protected function addGetPrimaryKey_MultiPK(&$script)
    {

        $script .= "
    /**
     * Returns the composite primary key for this object.
     * The array elements will be in same order as specified in XML.
     * @return array
     */
    public function getPrimaryKey()
    {
        \$pks = array();";
        $i = 0;
        foreach ($this->getTable()->getPrimaryKey() as $pk) {
            $script .= "
        \$pks[$i] = \$this->get".$pk->getPhpName()."();";
            $i++;
        } /* foreach */
        $script .= "

        return \$pks;
    }
";
    }
219458
public static function parse(array $argv)
    {
        $args = [];
        $options = [];

        for ($i = 0, $num = count($argv); $i < $num; $i++) {
            $arg = $argv[$i];
            if ($arg === '--') {//后缀所有内容都为参数
                $args[] = implode(' ', array_slice($argv, $i + 1));
                break;
            }
            if (substr($arg, 0, 2) === '--') {
                $key = substr($arg, 2);
                $value = true;
                if (($hadValue = strpos($arg, '=')) !== false) {
                    $key = substr($arg, 2, $hadValue - 2);
                    $value = substr($arg, $hadValue + 1);
                }
                if (array_key_exists($key, $options)) {
                    if (!is_array($options[$key])) {
                        $options[$key] = [$options[$key]];
                    }
                    $options[$key][] = $value;
                } else {
                    $options[$key] = $value;
                }
            } else if (substr($arg, 0, 1) === '-') {
                foreach (str_split(substr($arg, 1)) as $key) {
                    $options[$key] = true;
                }
            } else {
                $args[] = $arg;
            }
        }

        return [$args, $options];
    }
983706
final static function arg( $a, $default = null ){
		if( is_int($a) ){
			global $argv;
			// note: arg(0) will always be the script path
			return isset($argv[$a]) ? $argv[$a] : $default;
		}
		else {
			return isset(self::$args[$a]) ? self::$args[$a] : $default;
		}
	}
1127909
protected function runExtensionScript($script, array $arguments = [])
    {
        $this->log('d', 'Running custom extension script ' . $script . ' for extension ' . $this->getExtension()->getId());
        if (file_exists($script)) {
            require_once $script;
        } elseif (class_exists($script) && is_subclass_of($script, \oat\oatbox\action\Action::class)) {
            $action = new $script();

            if ($action instanceof ServiceLocatorAwareInterface) {
                $action->setServiceLocator($this->getServiceManager());
            }

            call_user_func($action, $arguments);
        } else {
            $error = new common_ext_InstallationException('Unable to run install script ' . $script);
            $error->setExtensionId($this->getExtension()->getId());

            throw $error;
        }
    }
1215174
public static function run($script)
    {
        $script = self::hideCloseTag($script);
        $script = self::hideOpenTag($script);

        return $script;
    }
834281
public static String run(String [] args) {
		if (args.length < 4) {
			return "Syntax error : args : " + " phpExec|default workingDirectory initPhpFile";
		}
		String [] l = new String[args.length - 1];
		for(int i = 3; i < args.length; i ++) {
			l[i - 1] = args[i];
		}
		l[0] = "--sud";
		l[1] = PHPSud.class.getCanonicalName() + ";" + args[0] + ";" + args[1] + ";" + args[2];
		StringBuilder cmd = new StringBuilder();
		for(String s : l) {
			cmd.append(s).append(" ");
		}
		System.out.println("Command line : " + cmd.toString());
		try {
			CommandLineRunner runner = new CommandLineRunner();
			RecorderMonitor recorderMonitor = new RecorderMonitor();
			LoggingMonitor loggingMonitor = new LoggingMonitor( System.out, System.err );
			runner.setMonitor(new CompositeSpecificationRunnerMonitor(recorderMonitor, loggingMonitor));
			runner.run(l);

			if (recorderMonitor.getStatistics().hasFailed()) {
				return "Some errors detected";
			}
			return "";
		} catch (Exception e) {
			return "Exception when executing tests " + e.toString();
		}
	}
687386
protected function runShell(Shell $shell, array $argv)
    {
        try {
            $shell->initialize();

            return $shell->runCommand($argv, true);
        } catch (StopException $e) {
            return $e->getCode();
        }
    }
1036457
@Override
  public int run(String[] args) {
    int rv = -1;

    try {
      rv = run2(args);
    }
    catch (org.apache.hadoop.mapred.FileAlreadyExistsException e) {
      if (ctrlc != null) { ctrlc.setComplete(); }
      System.out.println("ERROR: " + (e.getMessage() != null ? e.getMessage() : "(null)"));
      System.exit(1);
    }
    catch (Exception e) {
      System.out.println("ERROR: " + (e.getMessage() != null ? e.getMessage() : "(null)"));
      e.printStackTrace();
      System.exit(1);
    }

    return rv;
  }
1163882
private static function run(array $arguments)
	{
		// Unwind the args, figure out which ones were passed in as an array
		self::$stdin = null;
		$closureOut = false;
		foreach ($arguments as $k => $argument) {
			// If it's being passed in as an object, then pipe into stdin
			if (\is_object($argument)) {
				// If it's a anonymous function, then push stdout into it
				if ($argument instanceof \Closure) {
					$closureOut = $argument;
				} else {
					self::$stdin = (string) $argument;
				}
				unset($arguments[$k]);
			} elseif (\is_array($argument)) {
				if (Arrays::isAssoc($argument)) {
					// Ok, so we're passing in arguments
					$output = '';
					foreach ($argument as $key => $val) {
						if ($output !== '') {
							$output .= ' ';
						}
						// If you pass 'false', it'll ignore the arg altogether
						if ($val !== false) {
							// Figure out if it's a long or short commandline arg
							if (\strlen($key) === 1) {
								$output .= '-';
							} else {
								$output .= '--';
							}
							$output .= $key;
							// If you just pass in 'true', it'll just add the arg
							if ($val !== true) {
								$output .= ' ' . \escapeshellarg($val);
							}
						}
					}
					$arguments[$k] = $output;
				} else {
					// We're passing in an array, but it's not --key=val style
					$arguments[$k] = \implode(' ', $argument);
				}
			}
		}
		$shell = \implode(' ', $arguments);

		// Prepend the path
		if (\stripos(PHP_OS, 'win') !== 0) {
			$parts = \explode(' ', $shell);
			$parts[0] = \exec('which ' . $parts[0]);
			if ($parts[0] !== '') {
				$shell = \implode(' ', $parts);
			}
		}

		$descriptor_spec = [
			0 => ['pipe', 'r'], // Stdin
			1 => ['pipe', 'w'], // Stdout
			2 => ['pipe', 'w'] // Stderr
		];
		$process = \proc_open($shell, $descriptor_spec, $pipes);
		if (\is_resource($process)) {
			\fwrite($pipes[0], self::$stdin);
			\fclose($pipes[0]);
			$output = '';
			while (!\feof($pipes[1])) {
				$stdout = \fgets($pipes[1], 1024);
				if ($stdout === '') {
					break;
				}

				echo $stdout;

				if ($closureOut instanceof \Closure) {
					$closureOut($stdout);
				}
				$output .= $stdout;
			}
			$error_output = \trim(\stream_get_contents($pipes[2]));
			if (self::$displayStderr) {
				echo $error_output;
			}
			self::$output = $output;
			\fclose($pipes[1]);
			\fclose($pipes[2]);
			$return_value = \proc_close($process);
			if ($return_value !== 0) {
				throw new ShellException($error_output, $return_value);
			}
		} else {
			throw new ShellException('Process failed to spawn');
		}
	}
1025555
public function execute($code,$args=array()) {
        $this->executeTimes++;
        N('db_write',1); // 兼容代码
        $this->debug(true);
        $this->queryStr = 'execute:'.$code;
        $result   = $this->_mongo->execute($code,$args);
        $this->debug(false);
        if($result['ok']) {
            return $result['retval'];
        }else{
            E($result['errmsg']);
        }
    }
1295619
public function run(array $args)
    {
		if(count($args) < 3) {
            Index::error('Not enough arguments.', 'Usage: eve job random-mail subject=hi&body=hello...');
        }
		
		$data = array();
		
		if(strpos($args[2], '?') === 0) {
			parse_str(substr($args[2], 1), $data);
		} else {
			$data = json_decode($args[2], true);
		}
		
		$namespace = 'Eve';
		
		if(file_exists($this->cwd.'/composer.json')) {
			$json = $this('file', $this->cwd.'/composer.json')->getContent();
			$json = json_decode($json, true);

			if(isset($json['autoload']['psr-4'])
				&& is_array($json['autoload']['psr-4'])
			) {
				foreach($json['autoload']['psr-4'] as $namespace => $path) {
					if(strlen($path) === 0) {
						$namespace = substr($namespace, 0, -1);
						break;
					}
				}
			}
		}
		
		\Eve\Framework\Index::i($this->cwd, $namespace)
			// set default paths
			->defaultPaths()
			// set default database
			->defaultDatabases()
			->job($args[1])
			->setData($data)
			->run();
		
		Index::success('`'.$args[1].'` job has been successfully executed.');
    }
892981
public function execute($javascript, array $args = array())
    {
        $response = $this->request('POST', 'execute', json_encode(array(
            'script' => $javascript,
            'args'   => $args
        )));

        $data = json_decode($response->getContent(), true);

        return $data['value'];
    }
1013153
public function run(array $args)
    {
		if(count($args) < 3) {
            Index::error('Not enough arguments.', 'Usage: eve job random-mail subject=hi&body=hello...');
        }
		
		$data = array();
		
		if(strpos($args[2], '?') === 0) {
			parse_str(substr($args[2], 1), $data);
		} else {
			$data = json_decode($args[2], true);
		}
		
		$namespace = 'Eve';
		
		if(file_exists($this->cwd.'/composer.json')) {
			$json = $this('file', $this->cwd.'/composer.json')->getContent();
			$json = json_decode($json, true);

			if(isset($json['autoload']['psr-4'])
				&& is_array($json['autoload']['psr-4'])
			) {
				foreach($json['autoload']['psr-4'] as $namespace => $path) {
					if(strlen($path) === 0) {
						$namespace = substr($namespace, 0, -1);
						break;
					}
				}
			}
		}
		
		$queue = \Eve\Framework\Index::i($this->cwd, $namespace)
			// set default paths
			->defaultPaths()
			// set default database
			->defaultDatabases()
			->queue($args[1])
			->setData($data);
			
		if(isset($args[3]) && is_string($args[3])) {
			$queue->setPriority(trim($args[3]));
		} else if(isset($args[3]) && is_numeric($args[3])) {
			$queue->setPriority($args[3]);
		}
		
		if(isset($args[4]) && is_numeric($args[4])) {
			$queue->setDelay($args[4]);
		}
		
		$queue->save();
		
		Index::success('`'.$args[1].'` has been successfully queued.');
    }
773802
public function run($argc, $argv)
    {
        $this->addDefaultCommands();

        // @todo place better command parser here
        if ($argc == 1) {
            $run = $this->getDefaultCommand();
            $argv = [];
        } else {
            $run = $argv[1];
            $argv = array_slice($argv, 2);
        }

        $found = false;

        /** @var CommandInterface $command */
        foreach ($this->commands as $command) {
            // @todo prevent multiple commands having the same name (why?)
            if ($command->getName() == $run) {
                $command->run([], $argv);
                $found = true;
            }
        }

        // @todo more graceful end
        if (!$found) {
            echo "command unknown\n";
            // exit with error
            exit(1);
        }

        // this is running the react event loop, maybe this should run the actual commands too?
        $this->loop->run();
    }
1197410
public function script($src, $version=false){

        $list = [];

        foreach((array)$src as $script) {

            $type = 'text/javascript';
            $src  = $script;
            $load = '';

            if (is_array($script)) {
                extract($script);
            }

            $ispath = strpos($src, ':') !== false && !preg_match('#^(|http\:|https\:)//#', $src);
            $list[] = '<script src="'.($ispath ? $this->pathToUrl($src):$src).($version ? "?ver={$version}":"").'" type="'.$type.'" '.$load.'></script>';
        }

        return implode("\n", $list);
    }