Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/Symfony/Component/Console/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ final class Cursor
{
private $output;
private $input;
private $inputResource = null;

public function __construct(OutputInterface $output, $input = null)
{
$this->output = $output;
$this->input = $input ?? (\defined('STDIN') ? \STDIN : fopen('php://input', 'r+'));
$this->input = $input ?? (\defined('STDIN') ? \STDIN : $this->inputResource = fopen('php://input', 'r+'));
}

public function moveUp(int $lines = 1): self
Expand Down Expand Up @@ -145,7 +146,14 @@ public function getCurrentPosition(): array
static $isTtySupported;

if (null === $isTtySupported && \function_exists('proc_open')) {
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
$handle = @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
$isTtySupported = (bool) $handle;
if (false !== $handle) {
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($handle);
}
}

if (!$isTtySupported) {
Expand All @@ -165,4 +173,11 @@ public function getCurrentPosition(): array

return [$col, $row];
}

public function __destruct()
{
if (null !== $this->inputResource) {
fclose($this->inputResource);
}
}
}
26 changes: 23 additions & 3 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,14 @@ public static function isTtySupported(): bool
static $isTtySupported;

if (null === $isTtySupported) {
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
$handle = @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
$isTtySupported = (bool) $handle;
if (false !== $handle) {
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($handle);
}
}

return $isTtySupported;
Expand All @@ -1278,7 +1285,16 @@ public static function isPtySupported()
return $result = false;
}

return $result = (bool) @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
$handle = @proc_open('echo 1 >/dev/null', [['pty'], ['pty'], ['pty']], $pipes);
$result = (bool) $handle;
if (false !== $handle) {
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($handle);
}

return $result;
}

/**
Expand Down Expand Up @@ -1517,8 +1533,12 @@ private function doSignal(int $signal, bool $throwException): bool
$ok = @proc_terminate($this->process, $signal);
} elseif (\function_exists('posix_kill')) {
$ok = @posix_kill($pid, $signal);
} elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
} elseif ($handle = proc_open(sprintf('kill -%d %d', $signal, $pid), [2 => ['pipe', 'w']], $pipes)) {
$ok = false === fgets($pipes[2]);
fclose($pipes[2]);
proc_close($handle);
} else {
$ok = false;
}
if (!$ok) {
if ($throwException) {
Expand Down