Execute command.

If timeout <= 0 and callback is null then command will be executed in background

@param string $command
@param int $timeout
@param callable|null $callback
347498
public function execute($command, $timeout = 300, $callback = null)
    {
        if ($timeout > 0 || is_callable($callback)) {
            $this->executeCommand($command, $timeout, $callback);
        } else {
            $this->executeCommandInBackground($command);
        }
    }
137696
public static function setTimeout($timeout = 60) {
        if (!is_int($timeout) || $timeout < 0) {
            return false;
        }

        self::$timeout = $timeout;
        return true;
    }
732179
function setCallVoteTimeOut($timeout, $multicall = false)
    {
        if (!is_int($timeout)) {
            throw new InvalidArgumentException('timeout = ' . print_r($timeout, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($timeout), $multicall);
    }
46571
public function runRemoteCommand($cmd, $jail, $timeout = 120)
    {
        $user = $this->getEnvOption('user', $this->getCurrentUser());
        $sudo = $this->getEnvOption('sudo', false);
        $host = $this->getHostName();
        $sshConfig = $this->getSSHConfig();

        $cmdDelegate = $cmd;
        if ($sudo === true) {
            $cmdDelegate = sprintf('sudo %s', $cmd);
        }

        $hostPath = rtrim($this->getEnvOption('host_path'), '/');
        if ($jail && $this->getReleaseId() !== null) {
            $cmdDelegate = sprintf('cd %s/releases/%s && %s', $hostPath, $this->getReleaseId(), $cmdDelegate);
        } elseif ($jail) {
            $cmdDelegate = sprintf('cd %s && %s', $hostPath, $cmdDelegate);
        }

        $cmdRemote = str_replace('"', '\"', $cmdDelegate);
        $cmdLocal = sprintf('ssh -p %d %s %s@%s "%s"', $sshConfig['port'], $sshConfig['flags'], $user, $host, $cmdRemote);

        return $this->runLocalCommand($cmdLocal, $timeout);
    }
83617
public function exec($command, $runDir = null, Closure $callback = null, $timeout = null)
    {
        $process = new Process($command, $runDir);

        $process->setTimeout($timeout);

        $this->startedAt = Carbon::now();

        $process->run($callback);

        $this->endedAt = Carbon::now();

        return $process;
    }
830724
protected void waitForCommand(ITimerCallback callback, long timeout) throws WidgetTimeoutException {
		WaitForConditionTimer t = new WaitForConditionTimer(getByLocator(), callback);
		t.waitUntil(timeout);
	}
909836
public synchronized Operation timeout(@Nullable final Long timeout) {
        this.timeout = timeout == null || timeout > 0 ? timeout : null;
        return this;
    }
992384
def wait(self, timeout=None):
        
        timeout = ["--interval=%s" % timeout] if timeout else []
        cmdline = ["podman", "wait"] + timeout + [self._id or self.get_id()]
        return run_cmd(cmdline, return_output=True)
859185
public function exec($command, $callback = null)
    {
        $this->commandStack[] = [
            'command' => new Command($this->receiveCommand($command)),
            'callback' => $callback,
        ];

        return $this;
    }
843668
public function timeout($timeout = null)
    {
        $this->timeout = (null === $timeout) ? $this->defaultTimeout : $timeout;
        return $this;
    }
160180
public function run($commands, Closure $callback = null)
    {
        foreach ($this->connections as $connection) {
            $connection->run($commands, $callback);
        }
    }
859489
public function dispatch(CommandInterface $command, $callback = null){

	    if (!$command->getIdentity() && $this->getDefaultIdentity()) {
            $command->setIdentity($this->getDefaultIdentity());
	    }

	    $service     = $command->getService();
	    $operation   = $command->getOperation();
	    $context     = $command->getContext();
	    $argv        = $command->getParams();
	    $exception = null;

	    if(!$this->exists($command->getService())){
	        throw new ServiceNotFoundException(sprintf(
                'Service "%s" not found', $command->getService()));
	    }

	    $responses = null;

        // Notify, that a (background) job is about to start
        if ($command->getJob()) {
            $jobEvent = $this->createEvent(
                'job.start', $command);

            $this->getEventManager()
                ->trigger($jobEvent);
        }

		// Prepare and trigger init.<service>.<operation> event
		$initEvent = strtolower('init.'.$service.'.'.$operation);

		if(!$this->getEventManager()->getListeners($initEvent)->isEmpty()){
		    $e = $this->createEvent($initEvent, $command);

		    $eventResponses = $this->trigger(
	            $e,
	            function($response){if($response === false) return true;}
		    );

		    if($eventResponses->stopped() && $eventResponses->last() === false){
		        $responses = new ResponseCollection();
		        $responses->setStopped(true);
		    }
		}

		// Dispatch command
		if ($responses === null) {
		    try{
		        $responses = $this->getLoader()->getCommandManager()->trigger(
                    $command,
                    $callback
	            );
		    } catch(\Exception $ex) {
		        $exception = $ex;
		    }
		}

		// Prepare and trigger final.<service>.<operation> event
		$finalEvent = strtolower('final.'.$service.'.'.$operation);

		if(!$this->getEventManager()->getListeners($finalEvent)->isEmpty()){

		    $e = $this->createEvent($finalEvent, $command);

		    // Set exception
		    if ($exception) {
		        $e->setException($exception);
		    }

		    $this->trigger($e);

		    // Listeners have a chance to clear (or change) the exception
		    $exception = $e->getException();
		}

        // Notify that the job has ended
        if ($command->getJob()) {
            $jobEvent = $this->createEvent('job.end', $command);

            if ($exception) {
                $jobEvent->setException($exception);
            }
            $this->trigger($jobEvent);
        }

		// Throw exception if it still exists
		if ($exception instanceof \Exception) {
		    throw $exception;
		}

		return $responses;
	}
577051
public void executeAsyncTimed(final long timeout) {
		if (executeThread != null) {
			throw new IllegalStateException("use executable once per call");
		}
		final Executable nestedExec = this;
		helperExecutable = new Executable() {
			public Object execute() throws Throwable {
				return nestedExec.executeTimed(timeout);
			}
		};
		helperExecutable.executeAsync();
	}
1110780
function exec (cmd, callback) {
  debug('executing cmd', cmd)
  child_process.exec(cmd, function (err, stdout, stderr) {
    debug('command completed')
    if (err) {
      if (callback) {
        callback(err)
      }
    } else {
      if (callback) {
        callback(null, stdout, stderr)
      }
    }
  })
}
1254389
final public function runMulti($idleTimeout = null, callable $callback = null)
    {
        $this->resetRetryCount();

        $successful = false;
        while (! $successful && $this->getRetryCount() < $this->getRetryLimit()) {
            $successful = $this->runOnce($idleTimeout, $callback);
            $this->increaseRetryCount();

            yield $successful;
        }
    }
255606
public function runCommand( $command, $args = array(), $timeout = 86400 ) {

		// Convert a string args to an array
		if(!is_array($args)) $args = array($args);

		// Set a timeout so it's always set to either the default or the passed in parameter
		$timeout = ( isset( $timeout ) ? intval( $timeout ) : $this->connection->timeout );

                // Trim and then cast the command to a string, just to make sure
                $toWrite = strval( trim( $command ));

		// If the args is an array, then first escape double quotes in every element, then implode to strings delimted by enclosing quotes
		if( is_array( $args ) && ( count( $args ) > 0 )) {

			// This was causing an array to string conversion during the status command
			//$toWrite .= ' "' . implode('" "', str_replace( '"', '\"', $args )) . '"';

			// We need to escape any args that contain double quotes
			$args = array_map(function($element) {

				if(is_array($element)) {

					return array(str_replace('"', '\"', current($element)));

				} else {

					return str_replace('"', '\"', $element);
				}

			}, array_filter($args, function($element) {

				// Filter out any array elements that are also arrays
				return !is_array($element);
			}));

			// Make sure the args array is not now an empty array (in case it was filtered above)
			if (count($args) > 0) {

				$toWrite .= ' "' . implode('" "', $args) . '"';
			}
		}

		//Log::info( 'LxMPD runCommand toWrite', array($toWrite));

                // Write command to MPD socket
                $this->write( $toWrite );

		// Set the timeout in seconds
		$this->connection->setStreamTimeout( $timeout );

                // Read the response from the MPD socket
                $response = $this->read();

		// Set the timeout in seconds
		$this->connection->setStreamTimeout( $timeout );

		//Log::info( 'LxMPD runCommand response', array($response));
		//Log::info( 'LxMPD runCommand command', array($command));
		//Log::info( 'LxMPD runCommand args', array($args));

                // Return the parsed response array
                return $this->parse( $response, $command, $args );
        }
1265529
public function timeout($timeout = null, $connectTimeout = null)
    {
        if(null !== $timeout)
        {
            $this->timeout = $timeout;
        }
        if(null !== $connectTimeout)
        {
            $this->connectTimeout = $connectTimeout;
        }
        return $this;
    }