更改当前目录
@param $fd
@param $cmd
776028
function cmd_CWD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        if (($dir = $this->setUserDir($user, $cmd[1])) != false)
        {
            $this->send($fd, "250 OK. Current directory is " . $dir);
        }
        else
        {
            $this->send($fd, "550 Can't change directory to " . $cmd[1] . ": No such file or directory");
        }
    }
995247
public static function make( $cmd, $params )
	{
		if ( !is_array( $params ) )
		{
			$params = array( $params );
		}
		
		$forge = new static;
		
		if ( !method_exists( $forge, $cmd ) )
		{
			throw new CCException( "CCForge_Php - Command could not be found." );
		}
		
		return call_user_func_array( array( $forge, $cmd ), $params );
	}
1064458
function mkdir(path, fn) {
  shell.mkdir('-p', path);
  shell.chmod(755, path);
  console.log(chalk.cyan('   create:'), path);
  if (fn) fn();
}
257297
function cmd_USER($fd, $cmd)
    {
        if (preg_match("/^([a-z0-9]+)$/", $cmd[1]))
        {
            $user = $cmd[1];
            $this->connections[$fd]['user'] = $user;
            $this->users[$user]['fd'] = $fd;
            $this->send($fd, "331 User $user OK. Password required");
        }
        else
        {
            $this->send($fd, "530 Login authentication failed");
        }
    }
1044123
private function collectPathInfo(CommandInterface $cmd)
    {
        if (empty($this->bucket) && isset($cmd['Bucket'])) {
            $this->bucket = $cmd['Bucket'];
        }
        if (empty($this->key) && isset($cmd['Key'])) {
            $this->key = $cmd['Key'];
        }
        if (empty($this->filename) && isset($cmd['Body'])) {
            $this->filename = $cmd['Body']->getMetadata('uri');
        }
    }
1343464
public function execute($cmd, $data)
    {
        // Use pipes for STDIN, STDOUT, and STDERR
        $descr = array(
          0 => array(
            'pipe',
            'r'
          ) ,
          1 => array(
            'pipe',
            'w'
          ) ,
          2 => array(
            'pipe',
            'w'
          )
        );
        $pipes = [];

        // Start process, telling it to use STDIN for input and STDOUT for output.
        $cmd = escapeshellcmd($cmd);
        $process = proc_open($cmd, $descr, $pipes);

        // Get the data into pipe only if data is resource
        if (gettype($data) == "resource") {
            // Stream input to STDIN
            while (!feof($data)) {
                fwrite($pipes[0], fread($data, 1024));
            }

            // Close STDIN and the source data.
            fclose($pipes[0]);
            fclose($data);
        }

        // Wait for process to finish while reading STDOUT to a temp stream.
        // Otherwise the process can block indefinitely if STODUT gets bigger
        // than 4kb.
        $this->output = fopen("php://temp", 'w+');
        $exit_code = null;
        while ($exit_code === null) {
            $status = proc_get_status($process);
            if ($status['running'] === false) {
                $exit_code = $status['exitcode'];
            }

            $chunk = stream_get_contents($pipes[1]);
            if ($chunk !== false) {
                fwrite($this->output, $chunk);
            }
        }

        // Close STDOUT
        fclose($pipes[1]);

        // On error, extract message from STDERR and throw an exception.
        if ($exit_code != 0) {
            $msg = stream_get_contents($pipes[2]);
            $this->cleanup($pipes, $this->output, $process);
            if ($this->log) {
                $this->log->error('Process exited with non-zero code.', [
                  'exit_code' => $exit_code,
                  'stderr' => $msg,
                ]);
            }
            throw new \RuntimeException($msg, 500);
        }

        // Return a function that streams the output.
        return function () use ($pipes, $process) {
            rewind($this->output);
            while (!feof($this->output)) {
                echo fread($this->output, 1024);
                ob_flush();
                flush();
            }
            $this->cleanup($pipes, $this->output, $process);
        };
    }
1287828
public function helperExec($cmd)
    {
        if ($this->resolve('EXPLAIN')) {
            $this->output->writeln("# Task needs the following helper command:");
            $this->output->writeln("# " . str_replace("\n", "\\n", $cmd));
        }
        $ret = '';
        $this->executor->execute($cmd, $ret);
        return $ret;
    }
751760
public function setFd($fd, $bev = null)
    {
        $this->fd = $fd;
        if ($fd === false) {
            $this->finish();
            return;
        }
        $this->fdWrite = $this->pipes[0];
        $flags = !is_resource($this->fd) ? \EventBufferEvent::OPT_CLOSE_ON_FREE : 0;
        $flags |= \EventBufferEvent::OPT_DEFER_CALLBACKS; // buggy option

        if ($this->eventLoop === null) {
            $this->eventLoop = EventLoop::$instance;
        }
        $this->bev = $this->eventLoop->bufferEvent(
            $this->fd,
            0,
            [$this, 'onReadEv'],
            null,
            [$this, 'onStateEv']
        );
        $this->bevWrite = $this->eventLoop->bufferEvent(
            $this->fdWrite,
            0,
            null,
            [$this, 'onWriteEv'],
            null
        );
        if (!$this->bev || !$this->bevWrite) {
            $this->finish();
            return;
        }
        if ($this->priority !== null) {
            $this->bev->priority = $this->priority;
        }
        if ($this->timeout !== null) {
            $this->setTimeout($this->timeout);
        }
        if (!$this->bev->enable(\Event::READ | \Event::TIMEOUT | \Event::PERSIST)) {
            $this->finish();
            return;
        }
        if (!$this->bevWrite->enable(\Event::WRITE | \Event::TIMEOUT | \Event::PERSIST)) {
            $this->finish();
            return;
        }
        $this->bev->setWatermark(\Event::READ, $this->lowMark, $this->highMark);

        init:
        if (!$this->inited) {
            $this->inited = true;
            $this->init();
        }
    }
1012303
function cmd_PWD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $this->send($fd, "257 \"" . $this->getUserDir($user) . "\" is your current location");
    }
425176
protected function _runCmd($cmd, $content, $environment = null)
    {
        $Process = new AssetProcess();
        $Process->environment($environment);
        $Process->command($cmd)->run($content);

        if ($Process->error()) {
            throw new RuntimeException($Process->error());
        }
        return $Process->output();
    }
1260065
protected function addJobToExecFile($cmd)
    {
        $content = file_get_contents($this->crontabCommands);

        if( ! stristr($content, $cmd))
        {
            $content = $content . $this->getValidCommand() . $cmd . EOL;

            file_put_contents($this->crontabCommands, $content);
        }
    }
49836
function cmd_RETR($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $ftpsock = $this->getUserSock($user);
        if (($file = $this->getFile($user, $cmd[1])) != false)
        {
            $this->send($fd, "150 Connecting to client");
            if ($fp = fopen($file, "r"))
            {
                while (!feof($fp))
                {
                    $cont = fread($fp, 1024);
                    if (!fwrite($ftpsock, $cont)) break;
                }
                if (fclose($fp) and $this->closeUserSock($user))
                {
                    $this->send($fd, "226 File successfully transferred");
                }
                else
                {
                    $this->send($fd, "550 Error during file-transfer");
                }
            }
            else
            {
                $this->send($fd, "550 Can't open " . $cmd[1] . ": Permission denied");
            }
        }
        else
        {
            $this->send($fd, "550 Can't open " . $cmd[1] . ": No such file or directory");
        }
    }
1244780
protected function execCommand(string $cmd, ...$args)
    {
        $command = $this->predis->createCommand($cmd, $args);
        $response = $this->predis->executeCommand($command);

        if ($response instanceof ErrorInterface) {
            return false;
        }

        if ($response instanceof Status) {
            return $response->getPayload() === 'OK';
        }

        return $response;
    }
104686
private function exec($cmd, $input = '')
    {
        // Cannot use $_SERVER superglobal since that's empty during UnitUnishTestCase
        // getenv('HOME') isn't set on Windows and generates a Notice.
        if ($this->prefixExecWithExportHome) {
          $home = getenv('HOME');
          if (!is_writable($home)) {
              $cmd = 'export HOME=/tmp && ' . $cmd;
          }
        }
        $process = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
        fwrite($pipes[0], $input);
        fclose($pipes[0]);
        $stdout = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        fclose($pipes[2]);
        $rtn = proc_close($process);

        return [
            'stdout' => $stdout,
            'stderr' => $stderr,
            'return' => $rtn
        ];
    }
1251276
protected function run($cmd)
    {
        $path = getenv('PATH');

        if ($this->prependPath) {
            $path = $this->prependPath . PATH_SEPARATOR . $path;
        }

        $process = new Process($cmd, $this->currentDir(), array(
            'PATH' => $path,
        ));

        $process->run();

        $this->process = $process;

        return $process;
    }
1248407
public function inform($cmd, $params = [])
    {
        switch ($cmd) {
          case 'label': // module's short name for menu
            if (!empty($this->params['label'])) {
                $label = $this->params['label'];
                // try to translate label
                $tcCat = TranslationsBuilder::getBaseTransCategory($this);
                $tc = "{$tcCat}/module";
                if (!empty(Yii::$app->i18n->translations["{$tcCat}*"])) {
                    $label = Yii::t($tc, $this->params['label']);
                }
                return $label;
            } else {
                //return false;
                try {
                    $ms = Yii::$app->i18n->getMessageSource(static::$tc);
                } catch(InvalidConfigException $ex) {
                    $ms = false;
                }
                return ($ms ? Yii::t(static::$tc, 'Module') : 'Module') . ' ' . $this->uniqueId;
            }
            break;
          case 'sitetree-params-action': // return action in route format
            //if (empty($params['module_full_id'])) return false;
            if (!empty($this->params['sitetree-params-action'])) return $this->params['sitetree-params-action'];
            break;
//todo
        }
        return null;
    }
1148200
private function execCmd($cmd, &$stdout = null, &$stderr = null)
    {
        $descriptorspec = array(
            0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
            1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
            2 => array("pipe", "w")   // stderr is a file to write to
        );

        $pipes= array();
        $process = proc_open($cmd, $descriptorspec, $pipes);

        $stdout = "";
        $stderr = "";

        if (!is_resource($process)) {
            return false;
        }

        #close child's input imidiately
        fclose($pipes[0]);

        stream_set_blocking($pipes[1], false);
        stream_set_blocking($pipes[2], false);

        $todo= array($pipes[1],$pipes[2]);

        while (true) {
            $readstdout = [];
            $readstderr = [];

            if (false !== !feof($pipes[1])) {
                $readstdout[]= $pipes[1];
            }

            if (false !== !feof($pipes[2])) {
                $readstderr[]= $pipes[2];
            }

            if (empty($readstdout)) {
                break;
            }

            $write = null;
            $ex = null;
            $ready = stream_select($readstdout, $write, $ex, 2);

            if (false === $ready) {
                // probably dead process
                break;
            }

            foreach ($readstdout as $out) {
                $line = fread($out, 1024);
                $stdout.= $line;
            }

            foreach ($readstderr as $out) {
                $line = fread($out, 1024);
                $stderr.= $line;
            }
        }

        $stdout = strlen($stdout) > 0 ? $stdout : null;
        $stderr = strlen($stderr) > 0 ? $stderr : null;

        fclose($pipes[1]);
        fclose($pipes[2]);

        return proc_close($process);
    }