Skip to content

Commit 53441aa

Browse files
committed
adds support for PTY mode
1 parent 5ea5921 commit 53441aa

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Symfony/Component/Process/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-----
66

77
* added the ability to define an idle timeout
8+
* added support for PTY mode
89

910
2.3.0
1011
-----

src/Symfony/Component/Process/Process.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Process
6262
private $incrementalOutputOffset;
6363
private $incrementalErrorOutputOffset;
6464
private $tty;
65+
private $pty;
6566

6667
private $fileHandles;
6768
private $readBytes;
@@ -156,6 +157,7 @@ public function __construct($commandline, $cwd = null, array $env = null, $stdin
156157
}
157158
$this->stdin = $stdin;
158159
$this->setTimeout($timeout);
160+
$this->pty = false;
159161
$this->enhanceWindowsCompatibility = true;
160162
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
161163
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
@@ -915,6 +917,30 @@ public function isTty()
915917
return $this->tty;
916918
}
917919

920+
/**
921+
* Sets PTY mode.
922+
*
923+
* @param Boolean $bool
924+
*
925+
* @return self
926+
*/
927+
public function setPty($bool)
928+
{
929+
$this->pty = (Boolean) $bool;
930+
931+
return $this;
932+
}
933+
934+
/**
935+
* Returns PTY state.
936+
*
937+
* @return Boolean
938+
*/
939+
public function isPty()
940+
{
941+
return $this->pty;
942+
}
943+
918944
/**
919945
* Gets the working directory.
920946
*
@@ -1137,6 +1163,12 @@ private function getDescriptors()
11371163
array('file', '/dev/tty', 'w'),
11381164
array('file', '/dev/tty', 'w'),
11391165
);
1166+
} elseif ($this->pty) {
1167+
$descriptors = array(
1168+
array('pty'),
1169+
array('pty'),
1170+
array('pty'),
1171+
);
11401172
} else {
11411173
$descriptors = array(
11421174
array('pipe', 'r'), // stdin

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ public function testTTYCommand()
200200
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
201201
}
202202

203+
/**
204+
* @group pty
205+
*/
206+
public function testPTYCommand()
207+
{
208+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
209+
$this->markTestSkipped('Windows does not have PTY support.');
210+
}
211+
212+
$process = $this->getProcess('echo "foo"');
213+
$process->setPty(true);
214+
$process->run();
215+
216+
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
217+
$this->assertEquals("foo\r\n", $process->getOutput());
218+
}
219+
203220
public function testExitCodeText()
204221
{
205222
$process = $this->getProcess('');

0 commit comments

Comments
 (0)