Execute command in a child process.

@param callable $callback
@return bool.
426454
function run(callable $callback = null) {
        if (isset($this->res))
            return null;
        $this->res = proc_open($this->cmd, $this->descriptor_spec, $this->pipes, $this->cwd, $this->env);
        if ($this->res) {
            $this->stdout = new TcpConnection($this->pipes[1]);
            if (is_callable($this->onMessage))
                $this->stdout->onMessage = function ($conn, $data) {
                    ($this->onMessage)($this, $data);
                };
            if (is_callable($this->onClose))
                $this->stdout->onClose = function () {
                    ($this->onClose)($this);
                };
            stream_set_blocking($this->pipes[0], false);
            if (is_callable($callback))
                $callback($this);
            return true;
        }
        unset ($this->res);
        return false;
    }
1029628
public function send($callback)
    {
        $this->arguments[] = $callback;
        $this->redisAsynPool->__call($this->name, $this->arguments);
    }
503361
function execute(command, callback){
  exec(command, function(error, stdout, stderr){ callback(error, stdout); });
}
1004981
public function setCallback($callback)
    {
        if ($callback instanceof \OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface) {
            $callback = array($callback, 'execute');
        }
        $this->callback = $callback;

        return $this;
    }
1309490
public function runCommand($command, $allowFailures = false, $callback = null)
    {
        if (is_string($command)) {
            $command = $this->parseProcessArguments($command);
        }

        $builder = new ProcessBuilder($command);
        $builder
            ->setWorkingDirectory(getcwd())
            ->setTimeout(3600)
        ;
        $process = $builder->getProcess();

        $remover = function ($untrimmed) {
            return ltrim(rtrim($untrimmed, "'"), "'");
        };
        if ($this->output instanceof OutputInterface) {
            if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
                $commandLine = implode(' ', array_map($remover, explode(' ', $process->getCommandLine())));
                $this->output->writeln('<question>CMD</question> '.$commandLine);
            }
        }

        $process->run($callback);

        if (!$process->isSuccessful() && !$allowFailures) {
            throw new \RuntimeException(trim($process->getErrorOutput()), (int) $process->getExitCode());
        }

        return trim($process->getOutput());
    }
755481
protected function executeCommand($command, $timeout = 300, $callback = null)
    {
        $process = new Process($this->prepare($command), $this->cwd, null, null, $timeout);
        $process->run($callback);
        if (!$process->isSuccessful()) {
            throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', $command));
        }
    }
491790
public function tryUntil($callback)
    {
        try {
            return call_user_func_array($this->process, $this->args);
        } catch (\Exception $e) {
            if (in_array(get_class($e), $this->allowedExceptions)) {
                throw $e;
            }
        }

        $this->logger->warning(sprintf('[%s] Waiting until callback return a success', $this->logInfos['callable']));

        $startTime = time();
        $retry = 1;

        for (;;) {
            if ($callback instanceof YoloInterface) {
                $available = $callback->isAvailable();
            } else {
                $available = call_user_func($callback);
            }

            if (true === $available) {
                try {
                    return call_user_func_array($this->process, $this->args);
                } catch (\Exception $e) {
                    $this->logger->warning(sprintf('[%s] Can\'t perform action [%s/%s]', $this->logInfos['callable'], $retry, $this->maxRetry));

                    if (in_array(get_class($e), $this->allowedExceptions)) {
                        throw $e;
                    }

                    ++$retry;
                }

                if ($retry >= $this->maxRetry) {
                    $this->logger->error(sprintf('[%s] retry has failed, aborting [%s/%s]', $this->logInfos['callable'], $retry, $this->maxRetry));

                    $retryException = new YoloException('', 0, $e);
                    $retryException->setRetry($this->maxRetry);
                    $retryException->setTimeout($this->timeout);
                    throw $retryException;
                }
            } else {
                $this->logger->warning(sprintf('[%s] Can\'t perform action, waiting next tick', $this->logInfos['callable']));
            }

            if ($this->timeout > 0 && (time() - $startTime) >= $this->timeout) {
                $retryException = new YoloException('Timed out');
                $retryException->setRetry($this->maxRetry);
                $retryException->setTimeout($this->timeout);

                throw $retryException;
            }

            sleep(1);
        }
    }
859185
public function exec($command, $callback = null)
    {
        $this->commandStack[] = [
            'command' => new Command($this->receiveCommand($command)),
            'callback' => $callback,
        ];

        return $this;
    }
994845
protected static function callback($callback)
    {
        if( is_string($callback) && ! is_callable($callback) )
        {
            return self::controllerCallback($callback);
        }

        return $callback;
    }
765471
public function control(callable $callback, $context = null)
    {
        $this->control = $callback;
        $this->controlContext = $context;

        return $this;
    }
431933
public function callback($callback)
    {
        $t = $this;
        $args = array_slice(func_get_args(),1);

        // use an event handler to dispatch to the callback
        $this->_events->register('startTransaction', function($event, $connection) use ($t, $callback, $args) {
            $t->results []= call_user_func_array($callback, $args);
        });

        return $this;
    }
175388
private function triggerCallback($callback, $arguments)
    {
        if (is_array($callback)) {
            $this->import($callback[0]);
            return call_user_func_array(array($this->{$callback[0]}, $callback[1]), $arguments);
        } elseif (is_callable($callback)) {
            return call_user_func_array($callback, $arguments);
        }

        return null;
    }
493828
public function handle(callable $callBack = null)
    {
        $ip = $this->getIpAddress();

        $isAllowed = $this->listMerger->isAllowed($ip, $this->defaultState);

        if ($callBack !== null) {
            return call_user_func($callBack, array($this, $isAllowed));
        } else {
            return $isAllowed;
        }
    }
504608
public function run($commands, Closure $callback = null)
    {
        $commands = (array) $commands;
        $commands = implode(' && ', $commands);

        $this->previousStatus = 0;
        $process = new Process($commands);
        $process->setIdleTimeout(60 * 60);
        $process->run(function ($type, $line) use ($callback) {
            $callback($line);
        });

        $this->previousStatus = $process->getExitCode();
    }
1061546
public function eachChild($callback)
    {
        foreach ($this->children as $child) {
            call_user_func($callback, $child);
        }

        return $this;
    }
442874
private static function _checkCallback($cls, $callback, $context)
    {
        self::_initiateCallbacks($cls);
        foreach (self::$_callbacks[$cls][$callback] as $func) {
            if (!call_user_func(array($context, $func))) {
                return false;
            }
        }
        return true;
    }
266209
public function run(callable $callback, ...$params)
    {
        $item = array_shift($this->instances);
        if (empty($item)) {
            return call_user_func_array($callback, $params);
        }
        return $item->handle($callback, function () use ($callback, $params) {
            return $this->run($callback, ...$params);
        });
    }