getConsoleOutput() public method

This is useful in client code that just wants to show the user whatever the command printed. The programs will sometimes use STDOUT, sometimes STDERR, sometimes mistakenly STDOUT instead of STDERR etc. but it often doesn't matter, we just want to pass the output on to the user.
public getConsoleOutput ( ) : string
return string
Example #1
0
 /**
  * Pulls changes from another clone
  *
  * ## OPTIONS
  *
  * [--from=<name|path|url>]
  * : Where to pull from. Can be a clone name (specified previously during the
  * 'clone' command), a path or a URL. Defaults to 'origin' which is
  * automatically set in every clone by the 'clone' command.
  *
  * [--continue]
  * : Finishes the pull after solving merge conflicts.
  *
  * ## EXAMPLES
  *
  * Let's have a site 'wpsite' and a clone 'myclone' created from it. To pull the changes
  * from the clone back into the main site, use:
  *
  *     wp vp pull --from=myclone
  *
  * When in the clone, the pull can be run without any parameter:
  *
  *     wp vp pull
  *
  * This will pull the changes from 'origin' which was set to the parent site during the
  * 'clone' command.
  *
  */
 public function pull($args = [], $assoc_args = [])
 {
     if (!VersionPress::isActive()) {
         WP_CLI::error('This site is not tracked by VersionPress. Please run "wp vp activate" before cloning / merging.');
     }
     if (isset($assoc_args['continue'])) {
         $process = new Process('git diff --name-only --diff-filter=U', VP_PROJECT_ROOT);
         $process->run();
         if ($process->getConsoleOutput() !== '') {
             WP_CLI::error('There are still some conflicts. Please resolve them and run `wp vp pull --continue` again.');
         }
         $this->finishPull();
         return;
     }
     $remote = isset($assoc_args['from']) ? $assoc_args['from'] : 'origin';
     $process = VPCommandUtils::exec("git config --get remote." . ProcessUtils::escapeshellarg($remote) . ".url");
     $remoteUrl = $process->getConsoleOutput();
     if (is_dir($remoteUrl)) {
         $this->runVPInternalCommand('commit-frequently-written-entities', [], $remoteUrl);
     } else {
         // We currently do not support commiting frequently written entities for repositories on a different server
     }
     $this->switchMaintenance('on');
     $branchToPullFrom = 'master';
     // hardcoded until we support custom branches
     $pullCommand = 'git pull ' . ProcessUtils::escapeshellarg($remote) . ' ' . $branchToPullFrom;
     $process = VPCommandUtils::exec($pullCommand);
     if ($process->isSuccessful()) {
         WP_CLI::success("Pulled changes from '{$remote}'");
     } else {
         if (stripos($process->getConsoleOutput(), 'automatic merge failed') !== false) {
             WP_CLI::warning("");
             WP_CLI::warning("CONFLICTS DETECTED. Your options:");
             WP_CLI::warning("");
             WP_CLI::warning(" 1) Keep the conflicts. You will be able to resolve them manually.");
             WP_CLI::warning(" 2) Abort the process. The site will look like you never ran the pull.");
             WP_CLI::warning("");
             fwrite(STDOUT, "Choose 1 or 2: ");
             $answer = trim(fgets(STDIN));
             if ($answer == "1") {
                 WP_CLI::success("You've chosen to keep the conflicts on the disk. MAINTENANCE MODE IS STILL ON.");
                 WP_CLI::success("");
                 WP_CLI::success("Do this now:");
                 WP_CLI::success("");
                 WP_CLI::success(" 1. Resolve the conflicts manually as in a standard Git workflow");
                 WP_CLI::success(" 2. Stage and `git commit` the changes");
                 WP_CLI::success(" 3. Return here and run `wp vp pull --continue`");
                 WP_CLI::success("");
                 WP_CLI::success("That last step will turn the maintenance mode off.");
                 WP_CLI::success("You can also abort the merge manually by running `git merge --abort`");
                 exit;
             } else {
                 $process = VPCommandUtils::exec('git merge --abort');
                 if ($process->isSuccessful()) {
                     $this->switchMaintenance('off');
                     WP_CLI::success("Pull aborted, your site is now clean and running");
                     exit;
                 } else {
                     WP_CLI::error("Aborting pull failed, do it manually by executing 'git merge --abort'", false);
                     WP_CLI::error("and also don't fortget to turn off the maintenance mode.");
                 }
             }
         } else {
             // not a merge conflict, some other error
             $this->switchMaintenance('off');
             WP_CLI::error("Changes from {$remote} couldn't be pulled. Details:\n\n" . $process->getConsoleOutput());
         }
     }
     $this->finishPull();
 }
 /**
  * Executes a command. If the command is WP-CLI command (starts with "wp ...")
  *
  * @param string $command
  * @param string $executionPath Working directory for the command. If null, the path will be determined
  *   automatically.
  *
  * @param bool $debug
  * @param null|array $env
  * @return string When process execution is not successful
  * @throws Exception
  */
 private function exec($command, $executionPath = null, $debug = false, $env = null)
 {
     $command = $this->rewriteWpCliCommand($command);
     if (!$executionPath) {
         $executionPath = $this->siteConfig->path;
     }
     // Changing env variables for debugging
     // We don't need the xdebug enabled in the subprocesses,
     // but sometimes on the other hand we need it enabled only in the subprocess.
     $isDebug = isset($_SERVER["XDEBUG_CONFIG"]);
     $childEnv = $_SERVER;
     if ($isDebug == $debug) {
         // same as this process
     } elseif ($debug) {
         $childEnv["XDEBUG_CONFIG"] = "idekey=xdebug";
         // turn debug on
     } else {
         unset($childEnv["XDEBUG_CONFIG"]);
         // turn debug off
     }
     $childEnv = array_merge($childEnv, (array) $env);
     $process = new Process($command, $executionPath, $childEnv);
     $process->run();
     if (!$process->isSuccessful()) {
         throw new Exception("Error executing cmd '{$command}' from working directory " . "'{$executionPath}':\n{$process->getConsoleOutput()}");
     }
     return $process->getOutput();
 }