Execute the process and associate with this object.

@param string $cmd  Command to be executed
@param array|string  $args Arguments (strings)

@return self
2522
public function exec($cmd, $args = array())
    {
        // Arguments must be safe
        if (!is_array($args)) {
            $args = array($args);
        }
        foreach ($args as $val) {
            if (!is_string($val)) {
                throw new BaseException('You must specify arguments as strings');
            }
            $this->args[] = escapeshellarg($val);
        }

        // Command myst be safe
        $this->cmd = escapeshellcmd($cmd);

        $this->debug('Executing '.$cmd.($this->args ? ' '.implode(' ', $this->args) : ''));
        // Now do the execution
        $this->executeRaw($this->cmd.' '.implode(' ', $this->args));

        return $this;
    }
848259
protected function run($cmd/*, $options = NULL*/){
		$args = func_get_args ();
		$cmd = $this->_processCommand ( $args );
		exec ( $cmd . ' 2>&1', $output, $ret );

		if ($ret !== 0) {
			throw new GitException ( implode("<br>",$output), $ret );
		}

		return $this;
	}
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.' );
        }
    }
1095227
private function cmdReset($args)
    {
        $cmd = new ResetCommand($this->cwd);

        return $cmd->run(array_slice($args, 1));
    }
633707
public function run($args)
  {
    $this->args = $args;
    $command = $this->args['commands'][1];
    $path = $this->root.DIRECTORY_SEPARATOR.'cmd'.DIRECTORY_SEPARATOR.$command;
    if(!is_dir($path)){
      print $command.' doesn\'t appear to be a valid command!';
      return;
    }
    $file = $path.DIRECTORY_SEPARATOR.$this->helpFile;
    if(stream_resolve_include_path($file)){
       print file_get_contents($file);
    }
  }
937473
private static function exec(array $args)
    {
        $cmd = implode(' ', array_map('escapeshellarg', $args)) . ' 2>/dev/null';
        $process = proc_open($cmd, [1 => ['pipe', 'w']], $pipes);
        $output = stream_get_contents($pipes[1]);
        fclose($pipes[1]);
        if (proc_close($process) !== 0) {
            return false;
        }

        return $output;
    }
440343
public function get($command, $arguments = array())
    {
        $options = $this->getOptions();
        $consoleDir = $this->getConsoleDir();

        if (null === $consoleDir) {
            return;
        }

        $argumentString = '';

        foreach ($arguments as $argument) {
            $argumentString .= escapeshellarg($argument) . ' ';
        }

        $process = $this->executeCommand($consoleDir, $command . ' ' . $argumentString, false);

        echo $process->getOutput();
    }
841911
public function execute($args)
    {
        self::$definedProps = new Properties();
        $this->searchForThis = null;

        // 1) First handle any options which should always
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (in_array('-help', $args) || in_array('-h', $args)) {
            static::printUsage();

            return;
        }

        if (in_array('-version', $args) || in_array('-v', $args)) {
            static::printVersion();

            return;
        }

        if (in_array('-init', $args) || in_array('-i', $args)) {
            $key = array_search('-init', $args) ?: array_search('-i', $args);
            $path = isset($args[$key + 1]) ? $args[$key + 1] : null;

            self::init($path);

            return;
        }

        if (in_array('-diagnostics', $args)) {
            Diagnostics::doReport(new PrintStream(self::$out));

            return;
        }

        // 2) Next pull out stand-alone args.
        // Note: The order in which these are executed is important (if multiple of these options are specified)

        if (false !== ($key = array_search('-quiet', $args, true)) || false !== ($key = array_search(
            '-q',
            $args,
            true
        ))
        ) {
            self::$msgOutputLevel = Project::MSG_WARN;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-emacs', $args, true))
            || false !== ($key = array_search('-e', $args, true))
        ) {
            $this->emacsMode = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-verbose', $args, true))) {
            self::$msgOutputLevel = Project::MSG_VERBOSE;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-debug', $args, true))) {
            self::$msgOutputLevel = Project::MSG_DEBUG;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-silent', $args, true))
            || false !== ($key = array_search('-S', $args, true))
        ) {
            $this->silent = true;
            unset($args[$key]);
        }

        if (false !== ($key = array_search('-propertyfileoverride', $args, true))) {
            $this->propertyFileOverride = true;
            unset($args[$key]);
        }

        // 3) Finally, cycle through to parse remaining args
        //
        $keys = array_keys($args); // Use keys and iterate to max(keys) since there may be some gaps
        $max = $keys ? max($keys) : -1;
        for ($i = 0; $i <= $max; $i++) {
            if (!array_key_exists($i, $args)) {
                // skip this argument, since it must have been removed above.
                continue;
            }

            $arg = $args[$i];

            if ($arg == "-logfile") {
                try {
                    // see: http://phing.info/trac/ticket/65
                    if (!isset($args[$i + 1])) {
                        $msg = "You must specify a log file when using the -logfile argument\n";
                        throw new ConfigurationException($msg);
                    }

                    $logFile = new PhingFile($args[++$i]);
                    $out = new FileOutputStream($logFile); // overwrite
                    self::setOutputStream($out);
                    self::setErrorStream($out);
                    self::$isLogFileUsed = true;
                } catch (IOException $ioe) {
                    $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions.";
                    throw new ConfigurationException($msg, $ioe);
                }
            } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a buildfile when using the -buildfile argument.";
                    throw new ConfigurationException($msg);
                }

                $this->buildFile = new PhingFile($args[++$i]);
            } elseif ($arg == "-listener") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a listener class when using the -listener argument";
                    throw new ConfigurationException($msg);
                }

                $this->listeners[] = $args[++$i];
            } elseif (StringHelper::startsWith("-D", $arg)) {
                // Evaluating the property information //
                // Checking whether arg. is not just a switch, and next arg. does not starts with switch identifier
                if (('-D' == $arg) && (!StringHelper::startsWith('-', $args[$i + 1]))) {
                    $name = $args[++$i];
                } else {
                    $name = substr($arg, 2);
                }

                $value = null;
                $posEq = strpos($name, "=");
                if ($posEq !== false) {
                    $value = substr($name, $posEq + 1);
                    $name = substr($name, 0, $posEq);
                } elseif ($i < count($args) - 1 && !StringHelper::startsWith("-D", $args[$i + 1])) {
                    $value = $args[++$i];
                }
                self::$definedProps->setProperty($name, $value);
            } elseif ($arg == "-logger") {
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -logger argument";
                    throw new ConfigurationException($msg);
                }

                $this->loggerClassname = $args[++$i];
            } elseif ($arg == "-no-strict") {
                $this->strictMode = false;
            } elseif ($arg == "-strict") {
                $this->strictMode = true;
            } elseif ($arg == "-inputhandler") {
                if ($this->inputHandlerClassname !== null) {
                    throw new ConfigurationException("Only one input handler class may be specified.");
                }
                if (!isset($args[$i + 1])) {
                    $msg = "You must specify a classname when using the -inputhandler argument";
                    throw new ConfigurationException($msg);
                }

                $this->inputHandlerClassname = $args[++$i];
            } elseif ($arg === "-propertyfile") {
                $i = $this->handleArgPropertyFile($args, $i);
            } elseif ($arg === "-keep-going" || $arg === "-k") {
                $this->keepGoingMode = true;
            } elseif ($arg == "-longtargets") {
                self::$definedProps->setProperty('phing.showlongtargets', 1);
            } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") {
                // set the flag to display the targets and quit
                $this->projectHelp = true;
            } elseif ($arg == "-find") {
                // eat up next arg if present, default to build.xml
                if ($i < count($args) - 1) {
                    $this->searchForThis = $args[++$i];
                } else {
                    $this->searchForThis = self::DEFAULT_BUILD_FILENAME;
                }
            } elseif (substr($arg, 0, 1) == "-") {
                // we don't have any more args
                self::printUsage();
                self::$err->write(PHP_EOL);
                throw new ConfigurationException("Unknown argument: " . $arg);
            } else {
                // if it's no other arg, it may be the target
                $this->targets[] = $arg;
            }
        }

        // if buildFile was not specified on the command line,
        if ($this->buildFile === null) {
            // but -find then search for it
            if ($this->searchForThis !== null) {
                $this->buildFile = $this->_findBuildFile(self::getProperty("user.dir"), $this->searchForThis);
            } else {
                $this->buildFile = new PhingFile(self::DEFAULT_BUILD_FILENAME);
            }
        }

        try {
            // make sure buildfile (or buildfile.dist) exists
            if (!$this->buildFile->exists()) {
                $distFile = new PhingFile($this->buildFile->getAbsolutePath() . ".dist");
                if (!$distFile->exists()) {
                    throw new ConfigurationException(
                        "Buildfile: " . $this->buildFile->__toString() . " does not exist!"
                    );
                }
                $this->buildFile = $distFile;
            }

            // make sure it's not a directory
            if ($this->buildFile->isDirectory()) {
                throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is a dir!");
            }
        } catch (IOException $e) {
            // something else happened, buildfile probably not readable
            throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is not readable!");
        }

        $this->loadPropertyFiles();

        $this->readyToRun = true;
    }
1159007
public function execute($cmd, $failOnError = true)
    {
        $command = $this->createSupervisorControlCommand($cmd);
        $this->logger->debug('Executing: ' . $command);
        $p = new Process($command);
        $p->setWorkingDirectory($this->applicationDirectory);
        $p->run();
        if ($failOnError) {
            if ($p->getExitCode() !== 0) {
                $this->logger->critical(sprintf('supervisorctl returns code: %s', $p->getExitCodeText()));
            }
            $this->logger->debug('supervisorctl output: '. $p->getOutput());

            if ($p->getExitCode() !== 0) {
                throw new ProcessException($p);
            }
        }

        return $p;
    }
116464
public function runCommand($commandName, array $args = [])
    {
        $application = $this->getApplication();

        $command = $application->find($commandName);

        $arrayInput = new ArrayInput($args);

        $arrayInput->setInteractive(false);

        $command->run($arrayInput, $this->getOutput());
    }
1318431
public function exec($cmd): ProcessStatus
    {
        $cmd = sprintf('%s %s', $this->phpBinaryPath, $cmd . ' &');
        if (PHP_OS === 'WINNT') {
            $cmd = str_replace('/', '\\', $cmd);
            $cmd = str_replace('\\', '\\\\', $cmd);
        }
        if (PHP_SAPI !== 'cli') {
//            define('STDIN', fopen('php://stdin', 'r'));
            define('STDOUT', fopen('php://stdout', 'w'));
            define('STDERR', fopen('php://stderr', 'w'));
        }
        $pipes = [['pipe', 'r'], STDOUT, STDERR];
        $pipesOpened = [];
        Log::log($cmd);
        $resource = proc_open($cmd, $pipes, $pipesOpened, null, null, ['bypass_shell' => true]);
        if (false === $resource) {
            throw new \RuntimeException('Cannot be run ' . $cmd);
        }
        return new ProcessStatus($resource, $pipesOpened);
    }
760578
public function
	Run($cmd=null) {
	/*//
	@argv string HandlerName
	@argv array CommandArgumentList

	if given a string it will execute the handler defined under as that name.
	if given an array then it will process that array as though it was the
	_SERVER['argv'] data and execute as if that was the original command line
	given to the object creation.
	//*/

		$restore = false;
		$return = 0;

		////////
		////////

		if(is_array($cmd)) {
			// rewrite our input and option data with this subcommand
			// that was given to us. execute as though this array defined
			// the original command input.

			$restore = [ 'Inputs'=>$this->Inputs, 'Options'=>$this->Options ];

			$data = static::ParseCommandArgs($cmd,false);
			$this->Inputs = $data['Inputs'];
			$this->Options = $data['Options'];

			$cmd = $this->GetInputs();
		}

		////////
		////////

		if(!$cmd && !($cmd = $this->GetInput(1))) {
			if(!$this->DefaultHandlerName) {
				echo "No input provided.", PHP_EOL;
				return static::ErrorNoInput;

			}

			$cmd = [$this->DefaultHandlerName];
		}

		else {
			$cmd = $this->GetInputs();
		}

		////////
		////////

		$Commanded = FALSE;

		foreach($cmd as $cur) {
			$method = static::GetMethodFromCommand($cur);
			try {
				$return = $this->Run_ByMethod($method);
				$Commanded = TRUE;
			}
			catch(ClientHandlerException $e) {
				try {
					$return = $this->Run_ByCallable($cur);
					$Commanded = TRUE;
				}
				catch(ClientHandlerException $e) { }
			}

			if($Commanded && !$this->ChainCommands)
			break;
		}

		if(!$Commanded) {
			echo "no handler or method found for {$cur}", PHP_EOL;
			return static::ErrorNoHandler;
		}

		////////
		////////

		if($restore) {
			// restore the original input data before continuing on so that
			// we could continue processing the cli input data if needed.
			$this->Inputs = $restore['Inputs'];
			$this->Options = $restore['Options'];
		}

		return $return;
	}
114324
public function spawn($cmd, $options = array(), $start = true)
    {
        // Generate guid
        $guid = uniqid();
        // Get create directory
        $dir = !empty($options['dir']) ? $options['dir'] : sys_get_temp_dir();
        // Events name
        $types = array('stdin', 'stdout', 'stderr');
        // Files to descriptor
        $files = array();
        // Self
        $self = $this;

        // Define the stdin stdout and stderr files
        foreach ($types as $type) {
            $files[] = $file = $dir . '/' . $guid . '.' . $type;
            posix_mkfifo($file, 0600);
        }

        $child = $this->parallel(function ($process) use ($cmd, $files) {
            $pipes = array();

            // Make file descriptors for proc_open()
            $fd = array();
            foreach ($files as $i => $file) {
                $fd[] = array('file', $file, $i > 0 ? 'w' : 'r');
            }

            // Open pipe to run process
            $resource = proc_open($cmd, $fd, $pipes);

            if (!is_resource($resource)) {
                throw new \RuntimeException('Can not run "' . $cmd . '" using pipe open');
            }

            // Close all pipes
            foreach ($pipes as $pipe) {
                fclose($pipe);
            }

            proc_close($resource);
            exit;
        }, $options, $start);

        $child->on('fork', function () use (&$files, $child, $types, $self) {
            // Make file descriptor
            $pipes = array();
            foreach ($files as $i => $file) {
                $pipes[] = fopen($file, $i > 0 ? 'r' : 'w');
            }

            // Create tick process callback
            $tick = function () use ($pipes, $child, $types) {
                $readers = $pipes;

                // Select the streams
                if (empty($readers) || stream_select($readers, $null, $null, 0) <= 0) return;

                // Check which reader selected and emit event
                foreach ($readers as $reader) {
                    if (!is_resource($reader)) continue;
                    $index = array_search($reader, $pipes);
                    while (!feof($reader)) {
                        $child->emit($types[$index], fgets($reader));
                    }
                }
            };

            // Register tick function to check streams
            $self->on('tick', $tick);

            // Remove file when exit
            $child->on('exit', function () use ($tick, $self, &$files, &$pipes) {
                $self->removeListener('tick', $tick);
                foreach ($files as $file) {
                    unlink($file);
                }
                $files = $pipes = array();
            });
        });

        return $child;
    }
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);
            }
        }
    }
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;
    }
535220
public function exec($cmd, $args)
    {
        if (!$this->loaded) {
            return array('error' => $this->error(self::ERROR_CONF, self::ERROR_CONF_NO_VOL));
        }

        if (!$this->commandExists($cmd)) {
            return array('error' => $this->error(self::ERROR_UNKNOWN_CMD));
        }

        if (!empty($args['mimes']) && is_array($args['mimes'])) {
            foreach ($this->volumes as $id => $v) {
                $this->volumes[$id]->setMimesFilter($args['mimes']);
            }
        }

        $result = $this->$cmd($args);

        if (isset($result['removed'])) {
            foreach ($this->volumes as $volume) {
                $result['removed'] = array_merge($result['removed'], $volume->removed());
                $volume->resetRemoved();
            }
        }

        // call handlers for this command
        if (!empty($this->listeners[$cmd])) {
            foreach ($this->listeners[$cmd] as $handler) {
                if ((is_array($handler) && $handler[0]->{$handler[1]}($cmd, $result, $args, $this))
                ||  (!is_array($handler) && $handler($cmd, $result, $args, $this))) {
                    // handler return true to force sync client after command completed
                    $result['sync'] = true;
                }
            }
        }

        // replace removed files info with removed files hashes
        if (!empty($result['removed'])) {
            $removed = array();
            foreach ($result['removed'] as $file) {
                $removed[] = $file['hash'];
            }
            $result['removed'] = array_unique($removed);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['added'])) {
            $result['added'] = $this->filter($result['added']);
        }
        // remove hidden files and filter files by mimetypes
        if (!empty($result['changed'])) {
            $result['changed'] = $this->filter($result['changed']);
        }

        if ($this->debug || !empty($args['debug'])) {
            $result['debug'] = array(
                'connector' => 'php',
                'phpver'    => PHP_VERSION,
                'time'      => $this->utime() - $this->time,
                'memory'    => (function_exists('memory_get_peak_usage') ? ceil(memory_get_peak_usage()/1024).'Kb / ' : '').ceil(memory_get_usage()/1024).'Kb / '.ini_get('memory_limit'),
                'upload'    => $this->uploadDebug,
                'volumes'   => array(),
                'mountErrors' => $this->mountErrors
                );

            foreach ($this->volumes as $id => $volume) {
                $result['debug']['volumes'][] = $volume->debug();
            }
        }

        foreach ($this->volumes as $volume) {
            $volume->umount();
        }

        return $result;
    }
553671
public function execute(array $argv = [])
    {
        if (empty($argv)) {
            return $this->help();
        }

        $cmd = array_shift($argv);
        if (isset($this->commands[$cmd])) {
            return $this->commands[$cmd]->initialize($argv, $this);
        }

        return $this->help($argv);
    }