function drush_shell_proc_build

8.0.x exec.inc drush_shell_proc_build($site, $command = '', $cd = NULL, $interactive = FALSE)
6.x exec.inc drush_shell_proc_build($site, $command = '', $cd = NULL, $interactive = FALSE)
7.x exec.inc drush_shell_proc_build($site, $command = '', $cd = NULL, $interactive = FALSE)
5.x exec.inc drush_shell_proc_build($site, $command = '', $cd = NULL)
master exec.inc drush_shell_proc_build($site, $command = '', $cd = NULL, $interactive = FALSE)

Build an SSH string including an optional fragment of bash. Commands that use this should also merge drush_shell_proc_build_options() into their command options.

Parameters

array $site: A site alias record.

string $command: An optional bash fragment.

string $cd: An optional directory to change into before executing the $command. Set to boolean TRUE to change into $site['root'] if available.

boolean $interactive: Force creation of a tty

Return value

string A string suitable for execution with drush_shell_remote_exec().

See also

ssh_drush_command().

Related topics

2 calls to drush_shell_proc_build()
drush_ssh_site_ssh in commands/core/ssh.drush.inc
Command callback.
_drush_core_execute_cmd in commands/core/core.drush.inc
Helper function for drush_core_execute: run one shell command

File

includes/exec.inc, line 196
Functions for executing system commands. (e.g. exec(), system(), ...).

Code

function drush_shell_proc_build($site, $command = '', $cd = NULL, $interactive = FALSE) {
  // Build up the command. TODO: We maybe refactor this soon.
  $hostname = drush_remote_host($site);
  $ssh_options = drush_sitealias_get_option($site, 'ssh-options', "-o PasswordAuthentication=no");
  $os = drush_os($site);
  if (drush_sitealias_get_option($site, 'tty') || $interactive) {
    $ssh_options .= ' -t';
  }

  $cmd = "ssh " . $ssh_options . " " . $hostname;

  if ($cd === TRUE) {
    if (array_key_exists('root', $site)) {
      $cd = $site['root'];
    }
    else {
      $cd = FALSE;
    }
  }
  if ($cd) {
    $command = 'cd ' . drush_escapeshellarg($cd, $os) . ' && ' . $command;
  }

  if (!empty($command)) {
    if (!drush_get_option('escaped', FALSE)) {
      $cmd .= " " . drush_escapeshellarg($command, $os);
    }
    else {
      $cmd .= " $command";
    }
  }

  return $cmd;
}