|
@@ -15,6 +15,7 @@ namespace Composer\Util;
|
|
|
use Composer\IO\IOInterface;
|
|
|
use Symfony\Component\Process\Process;
|
|
|
use Symfony\Component\Process\ProcessUtils;
|
|
|
+use Symfony\Component\Process\Exception\RuntimeException;
|
|
|
|
|
|
/**
|
|
|
* @author Robert Schönthal <seroscho@googlemail.com>
|
|
@@ -41,7 +42,28 @@ class ProcessExecutor
|
|
|
* @param string $cwd the working directory
|
|
|
* @return int statuscode
|
|
|
*/
|
|
|
- public function execute($command, &$output = null, $cwd = null, $tty = false)
|
|
|
+ public function execute($command, &$output = null, $cwd = null)
|
|
|
+ {
|
|
|
+ if (func_num_args() > 1) {
|
|
|
+ return $this->doExecute($command, $cwd, false, $output);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->doExecute($command, $cwd, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * runs a process on the commandline in TTY mode
|
|
|
+ *
|
|
|
+ * @param string $command the command to execute
|
|
|
+ * @param string $cwd the working directory
|
|
|
+ * @return int statuscode
|
|
|
+ */
|
|
|
+ public function executeTty($command, $cwd = null)
|
|
|
+ {
|
|
|
+ return $this->doExecute($command, $cwd, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function doExecute($command, $cwd, $tty, &$output = null)
|
|
|
{
|
|
|
if ($this->io && $this->io->isDebug()) {
|
|
|
$safeCommand = preg_replace_callback('{://(?P<user>[^:/\s]+):(?P<password>[^@\s/]+)@}i', function ($m) {
|
|
@@ -61,7 +83,7 @@ class ProcessExecutor
|
|
|
$cwd = realpath(getcwd());
|
|
|
}
|
|
|
|
|
|
- $this->captureOutput = func_num_args() > 1;
|
|
|
+ $this->captureOutput = func_num_args() > 3;
|
|
|
$this->errorOutput = null;
|
|
|
|
|
|
// TODO in v3, commands should be passed in as arrays of cmd + args
|
|
@@ -71,7 +93,11 @@ class ProcessExecutor
|
|
|
$process = new Process($command, $cwd, null, null, static::getTimeout());
|
|
|
}
|
|
|
if (!Platform::isWindows() && $tty) {
|
|
|
- $process->setTty(true);
|
|
|
+ try {
|
|
|
+ $process->setTty(true);
|
|
|
+ } catch (RuntimeException $e) {
|
|
|
+ // ignore TTY enabling errors
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$callback = is_callable($output) ? $output : array($this, 'outputHandler');
|