删除文件
@param $fd
@param $cmd
346211
function cmd_DELE($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $file = $this->fillDirName($user, $cmd[1]);
        $this->debug("DEL: $file");
        if (!file_exists($file))
        {
            $this->send($fd, "550 Could not delete " . $cmd[1] . ": No such file or directory");
        }
        elseif (unlink($file))
        {
            $this->send($fd, "250 Deleted " . $cmd[1]);
        }
        else
        {
            $this->send($fd, "550 Could not delete " . $cmd[1] . ": Permission denied");
        }
    }
1017863
function cmd_RMD($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $dir = $this->fillDirName($user, $cmd[1]);
        $this->debug("RMDIR: $dir");
        if (is_dir(dirname($dir)) and is_dir($dir))
        {
            if (count(glob($dir . "/*")))
            {
                $this->send($fd, "550 Can't remove directory: Directory not empty");
            }
            elseif (rmdir($dir))
            {
                $this->send($fd, "250 The directory was successfully removed");
            }
            else
            {
                $this->send($fd, "550 Can't remove directory: Operation not permitted");
            }
        }
        elseif (is_dir(dirname($dir)) and file_exists($dir))
        {
            $this->send($fd, "550 Can't remove directory: Not a directory");
        }
        else
        {
            $this->send($fd, "550 Can't create directory: No such file or directory");
        }
    }
1243765
public function exec($cmd)
    {
        if (trim($cmd)) {
            $this->setOutputPrefix('');

            if ($this->resolve('DEBUG')) {
                $this->output->writeln('<comment># ' . join('::', Debug::$scope) . "</comment>");
            }

            if ($this->resolve('EXPLAIN')) {
                if ($this->resolve('INTERACTIVE')) {
                    $this->notice('interactive shell:');
                    $line = '( /bin/bash -c \'' . trim($cmd) . '\' )';
                } else {
                    $line = 'echo ' . escapeshellarg(trim($cmd)) . ' | ' . $this->resolve(array('SHELL'));
                }
                $this->output->writeln($line);
            } else {
                $this->executor->execute($cmd);
            }
        }
    }
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);
        };
    }
847512
public function run($cmd, array $args)
    {
        if (!isset($this->commands[$cmd])) {
            $this->error(sprintf('command %s not exists', $cmd));
        }
        $response = new Response();
        $driverId = isset($args['target']) ? $this->getDriverId($args['target']) : '';
        $driverId = !$driverId && isset($args['targets']) ? $this->getDriverId(current($args['targets'])) : $driverId;
        $interface = $this->getInterfaceByCmd($cmd);
        /*
         * @var string          $name
         * @var DriverInterface $driver
         */
        $data = null;
        foreach ($this->driverList as $name => $driver) {
            if (!$driverId || $driverId == $name) {
                if ($driver instanceof $interface) {
                    if ($driver->mount()) {
                        $data = $this->runCmd($driver, $cmd, $args, $response);
                    }
                    $driver->unmount();
                } else {
                    $this->error(sprintf('command "%s" not supported, please use interface "%s"', $cmd, $interface));
                }
                $this->addDisabledCommand($driver);
                $response->setOptions($driver->getOptions());
            }

            $response->addFile($driver->getRootFileInfo());
        }
        if (!empty($args['init'])) {
            $response->setApi(DriverInterface::VERSION);
        }

        return $data ?: $response;
    }
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();
    }
852018
private static function _pushTime($cmd)
        {
            // capture the time as early in the function as possible
            $mt = microtime();

            // set current running state depending on the command
            if ($cmd == static::CMD_START) {
                // check if the timer has already been started
                if (static::$_running === true) {
                    // ThinLog('Timer has already been started');
                    return;
                }

                // set current state
                static::$_running = true;

            } else if ($cmd == static::CMD_STOP) {
                // check if the timer is already stopped
                if (static::$_running === false) {
                    // ThinLog('Timer has already been stopped/paused or has not yet been started');
                    return;
                }

                // set current state
                static::$_running = false;

            } else {
                // fail execution of the script
                // ThinLog('Invalid command specified');
                return;
            }

            // recapture the time as close to the end of the function as possible
            if ($cmd === static::CMD_START) {
                $mt = microtime();
            }

            // split the time into components
            list($usec, $sec) = explode(' ', $mt);

            // typecast them to the required types
            $sec = (int) $sec;
            $usec = (float) $usec;
            $usec = (int) ($usec * static::USECDIV);

            // create the array
            $time = array(
                $cmd => array(
                    'sec'   => $sec,
                    'usec'  => $usec,
                ),
            );

            // add a time entry depending on the command
            if ($cmd == static::CMD_START) {
                array_push(static::$_queue, $time);

            } else if ($cmd == static::CMD_STOP) {
                $count = count(static::$_queue);
                $array =& static::$_queue[$count - 1];
                $array = array_merge($array, $time);
            }
        }
475278
final public static function exec(string $cmd, array $args=[]) {
		foreach ($args as $key => $val)
			$args[$key] = escapeshellarg($val);
		$cmd = vsprintf($cmd, $args);
		exec($cmd, $output, $retcode);
		if ($retcode !== 0)
			return false;
		return $output;
	}
1367541
protected function instantiateCommand($cmd)
    {
        if (!is_array($cmd)) {
            $cmd = [$cmd];
        }

        if (count($cmd)) {
            if (!is_numeric(current(array_keys($cmd)))) {
                $cmd = [$cmd];
            }
        }

        $command = new Command\SequenceCommand();

        foreach ($cmd as $c) {
            $cc = $this->instantiateSingleCommand($c);
            if ($cc instanceof CommandInterface) {
                $command->add($cc);
            } elseif (null !== $cc) {
                throw new \RuntimeException('Instantiated command is not a valid command', 16);
            }
        }

        return $command;
    }
817033
public static void execCmd(String cmd){
		Process p = null;
		try {
			Runtime rt = Runtime.getRuntime();
			p = rt.exec(cmd);
			// 获取进程的标准输入流
			final InputStream is1 = p.getInputStream();
			// 获取进城的错误流
			final InputStream is2 = p.getErrorStream();
			// 启动两个线程，一个线程负责读标准输出流，另一个负责读标准错误流
			new Thread() {
				public void run() {
					BufferedReader br1 = new BufferedReader(
							new InputStreamReader(is1));
					try {
						String line1 = null;
						while ((line1 = br1.readLine()) != null) {
							if (line1 != null) {
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					} finally {
						try {
							is1.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			}.start();
				
			new Thread() {
				public void run() {
					BufferedReader br2 = new BufferedReader(
							new InputStreamReader(is2));
					try {
						String line2 = null;
						while ((line2 = br2.readLine()) != null) {
							if (line2 != null) {
							}
						}
					} catch (IOException e) {
						e.printStackTrace();
					} finally {
						try {
							is2.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			}.start();
			
			p.waitFor();
			p.destroy();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {
				/*if( p.getErrorStream() != null ){
					p.getErrorStream().close();
				}
				if( p.getInputStream() != null ){
					p.getInputStream().close();
				}
				if( p.getOutputStream() != null ){
					p.getOutputStream().close();
				}*/
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
	}
879683
public function background_proc( $cmd ) {
		$descriptors = array(
			0 => STDIN,
			1 => array( 'pipe', 'w' ),
			2 => array( 'pipe', 'w' ),
		);

		$proc = proc_open( $cmd, $descriptors, $pipes, $this->variables['RUN_DIR'], self::get_process_env_variables() );

		sleep(1);

		$status = proc_get_status( $proc );

		if ( !$status['running'] ) {
			$stderr = is_resource( $pipes[2] ) ? ( ': ' . stream_get_contents( $pipes[2] ) ) : '';
			throw new RuntimeException( sprintf( "Failed to start background process '%s'%s.", $cmd, $stderr ) );
		} else {
			$this->running_procs[] = $proc;
		}
	}
551734
public static function init(Event $event, ScriptInterface $cmd)
    {
        if (!self::$_inited) {
            try {
                self::$_event   = $event;
                self::$_cmd     = $cmd;
                if (false===@class_exists('\WebDocBook\Filesystem\Helper')) {
                    include_once    __DIR__.'/../Filesystem/Helper.php';
                }
                if (false===@class_exists('\WebDocBook\Kernel')) {
                    include_once    __DIR__.'/../Kernel.php';
                }
                self::parseArguments();
                if (!defined(\WebDocBook\Kernel::BASEDIR_CONSTNAME)) {
                    self::parseExtra();
                }
                \WebDocBook\Kernel::boot(true);
            } catch (\Exception $e) {
                self::error($e);
            }
            self::$_inited = true;
        }
    }
1120392
private function send_req($cmd, $params) {
        $req = [$cmd];
        foreach ($params as $p) {
            if (is_array($p)) {
                $req = array_merge($req, $p);
            } else {
                $req[] = $p;
            }
        }

        return $this->send($req);
    }
472756
protected function onFileMoved($cmd, $result, $args, $elfinder) {
    $addedFiles = $result['added'];
    $removedFiles = $result['removed'];
    for ($i=0, $count=sizeof($removedFiles); $i<$count; $i++) {
      $source = $removedFiles[$i]['realpath'];
      $target = $elfinder->realpath($addedFiles[$i]['hash']);
    }
    $logger = $this->getLogger();
    $logger->debug($cmd." file: ".$source." -> ".$target);
  }
604988
private function readCSVLine($fd)
    {
        for (; ;) {
            $line = @fgetcsv($fd, 0, ',', '"');
            if ($line === false) {
                break;
            }
            if ($line === null) {
                throw new Exception('Error in CSV file');
            }
            yield $line;
        }
    }
1082289
public function executeCommand($cmd, $timeout = 300)
    {
        $php = escapeshellarg($this->getPhp());
        $process = new Process($php.' '.$this->root_dir.'console '.$cmd, $this->root_dir.'/../', null, null, $timeout);
        $process->run(function ($type, $buffer) {
            echo $buffer;
        });

        if (!$process->isSuccessful()) {
            throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', $cmd));
        }
    }
682166
protected function _runCmd( $cmd )
    {
        if ( !empty( $cmd ) )
        {
            if ( is_array( $cmd ) )
            {
                $cmd = implode( ' && ', $cmd );
            }
            if ( $this->_isWindows() )
            {
                if ( function_exists( 'popen' ) && function_exists( 'pclose' ) )
                {
                    pclose( popen( 'start / B ' . $cmd, 'r' ) );
                }
                else
                {
                    if ( $this->messaging === true )
                    {
                        $this->error( 'Windows php.exe should support \'popen\'|\'pclose\' commands to proper functionality' );
                    }
                }
            }
            else
            {
                if ( function_exists( 'exec' ) )
                {
                    exec( $cmd );
                }
                else
                {
                    if ( $this->messaging === true )
                    {
                        $this->error( 'linux php-cli should support \'exec\' command to proper functionality' );
                    }
                }
            }
        }
        else
        {
            $this->error( 'Command is empty. Check Requirements first.' );
        }
    }