Processes called command and returns it's output.

@access 	public
@return 	<void>
346482
public function watchOutput()
	{
		$arguments = $_SERVER['argv'];
		unset($arguments[0]);
		$argumentsCount = $_SERVER['argc'] - 1;
		$arguments = array_values($arguments);

		if ($argumentsCount > 0) {
			$commandId = $arguments[0];

			if (!Command::hasCommand($commandId)) {
				return $this->env->sendOutput(sprintf('[%s] is not a valid runnable id', $commandId), 'red');
			}

			$command = Command::getCommandById($commandId);
			$runnableCmds = $command->runnableCommands();

			if (isset($arguments[1])) {
				if (!isset($runnableCmds[$arguments[1]])) {
					return $this->error(sprintf('Command %s is an invalid command', $arguments[1]), 'red');
				}

				unset($arguments[0]);
			}

			$arguments = array_values($arguments);

			if (count($arguments) > 0 && isset($runnableCmds[$arguments[0]])) {
				// Check number of arguments passed to command and validate.
				$commandArgumentLength = $runnableCmds[$arguments[0]];

				// validate command with infinite arguments.
				if ($commandArgumentLength == ':i' && (count($arguments) - 1) == 0) {
					return $this->error(sprintf('[%s] command requires at least one argument', $arguments[0]), 'red');
				}

				// validate command with no arguments.
				if ($commandArgumentLength == ':none' && (count($arguments) - 1) > 0) {
					return $this->error(sprintf('[%s] command may not accept any argument', $arguments[0]), 'red');
				}

				if (is_integer($commandArgumentLength) && (count($arguments) - 1) > $commandArgumentLength) {
					$this->error(sprintf('[%s] command requires exactly [%d] argument(s)', $arguments[0], $commandArgumentLength));
				}
			}

			return $command->run($arguments, $argumentsCount);
		}
	}
158802
public function executeCommand()
    {
        $this->adapter->setCommandArray($this->commandArray);
        $result = $this->adapter->execute();
        $commandArrayUsed = $this->adapter->getCommandArray();
        $this->clearCommandArray();
        $this->checkResultForError($result, $commandArrayUsed);
        return $result;
    }
1139226
protected function process(): void
    {
        list($commandName, $actionName) = $this->checkArguments();

        $this->options = array_merge(
            $this->extractShortOptionsWithParams(),
            $this->extractShortOptionsVoid(),
            $this->extractLongOptionsWithValues(),
            $this->extractLongOptionsVoid()
        );

        $this->setDomainName($commandName);
        $this->setActionName($actionName);
        $this->analyzeAndSetParams();
    }
917597
protected function compileCommand()
    {
        $output = ProcessUtils::escapeArgument($this->output);

        $redirect = $this->shouldAppendOutput ? ' >> ' : ' > ';

        if (! $this->runInBackground) {
            return $this->command .$redirect .$output .' 2>&1';
        }

        $delimiter = windows_os() ? '&' : ';';

        $phpBinary = ProcessUtils::escapeArgument(
            with(new PhpExecutableFinder)->find(false)
        );

        $forgeBinary = defined('FORGE_BINARY') ? ProcessUtils::escapeArgument(FORGE_BINARY) : 'forge';

        $finished = $phpBinary .' ' .$forgeBinary .' schedule:finish ' . ProcessUtils::escapeArgument($this->mutexName());

        return '(' .$this->command .$redirect .$output .' 2>&1 ' .$delimiter .' ' .$finished .') > '
            . ProcessUtils::escapeArgument($this->getDefaultOutput()) .' 2>&1 &';
    }
1308962
public function exec()
    {
        $http = $this->argument('http');
        //
        $process = Router::post($http);
        //
        $this->show($process);
    }
700535
protected function doExecute()
	{
		$input  = $this->getConsoleInput();
		$output = $this->getConsoleOutput();

		// If requesting the version, short circuit the application and send the version data
		if ($input->hasParameterOption(['--version', '-V'], true))
		{
			$output->writeln($this->getLongVersion());

			return 0;
		}

		$name = $this->getCommandName($input);

		// Redirect to the help command if requested
		if ($input->hasParameterOption(['--help', '-h'], true))
		{
			// If no command name was given, use the help command with a minimal input; otherwise flag the request for processing later
			if (!$name)
			{
				$name  = 'help';
				$input = new ArrayInput(['command_name' => $this->defaultCommand]);
			}
			else
			{
				$this->wantsHelp = true;
			}
		}

		// If we still do not have a command name, then the user has requested the application's default command
		if (!$name)
		{
			$name       = $this->defaultCommand;
			$definition = $this->getDefinition();

			// Overwrite the default value of the command argument with the default command name
			$definition->setArguments(
				array_merge(
					$definition->getArguments(),
					[
						'command' => new InputArgument(
							'command',
							InputArgument::OPTIONAL,
							$definition->getArgument('command')->getDescription(),
							$name
						),
					]
				)
			);
		}

		try
		{
			$this->runningCommand = null;

			$command = $this->getCommand($name);
		}
		catch (\Throwable $e)
		{
			if ($e instanceof CommandNotFoundException && !($e instanceof NamespaceNotFoundException))
			{
				(new SymfonyStyle($input, $output))->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error');
			}

			$event = new CommandErrorEvent($e, $this);

			$this->dispatchEvent(ConsoleEvents::COMMAND_ERROR, $event);

			if ($event->getExitCode() === 0)
			{
				return 0;
			}

			$e = $event->getError();

			throw $e;
		}

		$this->runningCommand = $command;
		$exitCode             = $this->runCommand($command, $input, $output);
		$this->runningCommand = null;

		return $exitCode;
	}
1142074
private function nodeJsCommand()
    {

        // todo check nodejs exists in windows os
        return true;
        $found = false;
        foreach (['node', 'nodejs'] as $command) {
            $this->process->setCommandLine('which ' . $command);
            $this->process->setTimeout(null);
            $this->process->run();

            if ($this->process->isSuccessful()) {
                $found = true;
                break;
            }
        }

        if (!$found) {
            $this->console->error('node.js was not found');
            $this->errors =  true;
        }
    }
210656
protected function _processes()
    {
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
            $processes['*'] = 0;
            foreach ($lines as $line) {
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
                    $processes['*']++;
                    $state = $ar_buf[1];
                    if ($state == 'L') $state = 'D'; //linux format
                    elseif ($state == 'I') $state = 'S';
                    if (isset($processes[$state])) {
                        $processes[$state]++;
                    } else {
                        $processes[$state] = 1;
                    }
                }
            }
            if ($processes['*'] > 0) {
                $this->sys->setProcesses($processes);
            }
        }
    }
792976
public function execute()
    {
        list($ignore) = $this->getFlags();

        $phplint = $this->phpci->findBinary('parallel-lint');

        $cmd = $phplint . ' -e %s' . '%s %s "%s"';
        $success = $this->phpci->executeCommand(
            $cmd,
            $this->extensions,
            ($this->shortTag ? ' -s' : ''),
            $ignore,
            $this->directory
        );

        $output = $this->phpci->getLastOutput();

        $matches = array();
        if (preg_match_all('/Parse error\:/', $output, $matches)) {
            $this->build->storeMeta('phplint-errors', count($matches[0]));
        }

        return $success;
    }
1349850
public function main() {
        $this->stdout->styles('success', array('text' => 'green'));

        $this->hr(1);
        $this->out(sprintf('%s Steps:', $this->name));

        $counter = 1;

        foreach ($this->steps as $method) {
            $this->steps($counter);

            try {
                if (!call_user_func(array($this, $method))) {
                    $this->err('<error>Process aborted!</error>');
                    break;
                }
            } catch (Exception $e) {
                $this->err(sprintf('<error>Unexpected error has occurred; %s</error>', $e->getMessage()));
                break;
            }

            $counter++;
        }
    }
190348
public function run()
    {
        // If the truthTest failed, don't run
        if ($this->truthTest !== true) {
            return false;
        }

        // If overlapping, don't run
        if ($this->isOverlapping()) {
            return false;
        }

        // Write lock file if necessary
        $this->createLockFile();

        // Call before if required
        if (is_callable($this->before)) {
            call_user_func($this->before);
        }

        // If command is callable...
        if (is_callable($this->command)) {
            $this->output = $this->exec();
        } else {
            $args = \is_string($this->args) ? $this->args : implode(' ', $this->args);
            $command = $this->command . ' ' . $args;
            $process = new Process($command);

            $this->process = $process;

            if ($this->runInBackground()) {
                $process->start();
            } else {
                $process->run();
                $this->finalize();
            }
        }

        return true;
    }
1224062
public function getProcess(): Process
    {
        if (count($this->prefix) === 0 && count($this->arguments) === 0) {
            throw new MethodCallException('You must add arguments before calling getProcess()');
        }

        $arguments = array_merge($this->prefix, $this->arguments);
        $command = implode(' ', array_map('escapeshellarg', $arguments));

        if ($this->inheritEnv) {
            $env = array_replace($_SERVER, $this->environment);
        } else {
            $env = $this->environment;
        }

        $process = new Process(
            $command,
            $this->directory,
            $env,
            $this->input,
            $this->timeout,
            $this->stdout,
            $this->stderr
        );

        if ($this->outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }
577426
public function exec(): bool
    {
        $process = proc_open(
            $this->command,
            $this->spec,
            $pipes,
            $this->cwd,
            $this->env
        );

        if (is_resource($process)) {
            if ($this->spec[self::STDIN][0] === "pipe") {
                fwrite($pipes[0], $this->stdin);
                fclose($pipes[0]);
            }
            if ($this->spec[self::STDOUT][0] === "pipe") {
                $this->stdout = stream_get_contents($pipes[1]);
                fclose($pipes[1]);
            }
            if ($this->spec[self::STDERR][0] === "pipe") {
                $this->stderr = stream_get_contents($pipes[2]);
                fclose($pipes[2]);
            }
            $this->exitcode = proc_close($process);
        }
        return ($this->exitcode === 0);
    }
321914
public function run()
    {
        if ($this->opts->error !== null) {
            if ($this->opts->error !== '') {
                $top = '{cmd}: ' . $this->opts->error;
            } else {
                $top = '';
            }
            $this->usage($top);
            return $this->io;
        }
        if (!$this->loadOpts()) {
            return $this->io;
        }
        $this->process();
        return $this->io;
    }
952552
protected function doExecute()
	{
		$args = $this->input->args;

		$command = $this->getDescribedCommand($args);

		if (!$command->getApplication())
		{
			$command->setApplication($this->application);
		}

		$descriptor = $this->getDescriptor();

		/** @var $command Command */
		$rendered = $descriptor->describe($command);

		$this->out($rendered);

		return;
	}
890153
public function run()
    {
        $result = '';
        $result .= $this->getTitle();

        $dir = getcwd() . '/vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR;

        if (isset($this->params['version'])) {
            passthru($dir . 'phpunit --version');
            $result .= 'Humus PHPUnit Module ' . Version::VERSION;
            return $result;
        }


        if (isset($this->params['help'])) {
            $console = $this->console;

            $usage = $this->usage;
            if (!count($usage)) {
                return $result;
            }

            $result .= "\n";

            $table     = false;
            $tableCols = 0;
            $tableType = 0;

            if (is_string($usage)) {
                // It's a plain string - output as is
                $result .= $usage . "\n";
                return $result;
            }

            // It's an array, analyze it
            foreach ($usage as $a => $b) {
                /*
                 * 'invocation method' => 'explanation'
                 */
                if (is_string($a) && is_string($b)) {
                    if (($tableCols !== 2 || $tableType != 1) && $table !== false) {
                        // render last table
                        $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                        $table   = false;

                        // add extra newline for clarity
                        $result .= "\n";
                    }

                    // Colorize the command
                    $a = $console->colorize($a, ColorInterface::GREEN);

                    $tableCols = 2;
                    $tableType = 1;
                    $table[]   = array($a, $b);
                    continue;
                }

                /*
                 * array('--param', '--explanation')
                 */
                if (is_array($b)) {
                    if ((count($b) != $tableCols || $tableType != 2) && $table !== false) {
                        // render last table
                        $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                        $table   = false;

                        // add extra newline for clarity
                        $result .= "\n";
                    }

                    $tableCols = count($b);
                    $tableType = 2;
                    $table[]   = $b;
                    continue;
                }

                /*
                 * 'A single line of text'
                 */
                if ($table !== false) {
                    // render last table
                    $result .= $this->renderTable($table, $tableCols, $console->getWidth());
                    $table   = false;

                    // add extra newline for clarity
                    $result .= "\n";
                }

                $tableType = 0;
                $result   .= $b . "\n";
            }

            // Finish last table
            if ($table !== false) {
                $result .= $this->renderTable($table, $tableCols, $console->getWidth());
            }

            return $result;
        }

        foreach ($this->tests as $module => $paths) {
            if (isset($this->params['modules'])) {
                $modules = explode(',', $this->params['modules']);
                if (!in_array($module, $modules)) {
                    continue;
                }
            }
            foreach ($paths as $path) {
                $result .= $this->getModuleOutput($module);
                $params = join(' ', $this->params);
                $returnVar = null;
                ob_start();
                passthru($dir . 'phpunit -c ' . $path . ' ' . $params, $returnVar);
                $result .= ob_get_contents();
                ob_clean();
                if ($this->exitCode == 0 && $returnVar != 0) {
                    $this->exitCode = $returnVar;
                    if (isset($this->params['stop-on-module-failure'])) {
                        $result .= "\nAll done.";
                        return $result;
                    }
                }
            }

        }
        $result .= "\nAll done.";
        return $result;
    }
1117489
public function run() {
        // Use the global $argv variable to retrieve command-line arguments
        global $argv;
        
        // index[0] is the script name and index[1] is the command name
        if (isset($argv[1])) {
            // Get the command through map
            $commandName = strtolower($argv[1]);

            if (isset($this->_commands[$commandName])) {
                $cmd = $this->_commands[$commandName];

                // Execute the command
                return call_user_func($cmd, $this->_input, $this->_output);
            } else {
                // Command not found
                exit('Command not found: "' . $commandName . '"' . PHP_EOL);
            }
        }

        // Call the default command if set
        if (!is_null($this->_default) && is_callable($this->_default)) {
            return call_user_func($this->_default, $this->_input, $this->_output);
        }
    }