adds support for PTY mode
This commit is contained in:
parent
5ea5921918
commit
53441aa3d0
@ -5,6 +5,7 @@ CHANGELOG
|
||||
-----
|
||||
|
||||
* added the ability to define an idle timeout
|
||||
* added support for PTY mode
|
||||
|
||||
2.3.0
|
||||
-----
|
||||
|
@ -62,6 +62,7 @@ class Process
|
||||
private $incrementalOutputOffset;
|
||||
private $incrementalErrorOutputOffset;
|
||||
private $tty;
|
||||
private $pty;
|
||||
|
||||
private $fileHandles;
|
||||
private $readBytes;
|
||||
@ -156,6 +157,7 @@ class Process
|
||||
}
|
||||
$this->stdin = $stdin;
|
||||
$this->setTimeout($timeout);
|
||||
$this->pty = false;
|
||||
$this->enhanceWindowsCompatibility = true;
|
||||
$this->enhanceSigchildCompatibility = !defined('PHP_WINDOWS_VERSION_BUILD') && $this->isSigchildEnabled();
|
||||
$this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
|
||||
@ -915,6 +917,30 @@ class Process
|
||||
return $this->tty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PTY mode.
|
||||
*
|
||||
* @param Boolean $bool
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPty($bool)
|
||||
{
|
||||
$this->pty = (Boolean) $bool;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PTY state.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
public function isPty()
|
||||
{
|
||||
return $this->pty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the working directory.
|
||||
*
|
||||
@ -1137,6 +1163,12 @@ class Process
|
||||
array('file', '/dev/tty', 'w'),
|
||||
array('file', '/dev/tty', 'w'),
|
||||
);
|
||||
} elseif ($this->pty) {
|
||||
$descriptors = array(
|
||||
array('pty'),
|
||||
array('pty'),
|
||||
array('pty'),
|
||||
);
|
||||
} else {
|
||||
$descriptors = array(
|
||||
array('pipe', 'r'), // stdin
|
||||
|
@ -200,6 +200,23 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group pty
|
||||
*/
|
||||
public function testPTYCommand()
|
||||
{
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||
$this->markTestSkipped('Windows does not have PTY support.');
|
||||
}
|
||||
|
||||
$process = $this->getProcess('echo "foo"');
|
||||
$process->setPty(true);
|
||||
$process->run();
|
||||
|
||||
$this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
|
||||
$this->assertEquals("foo\r\n", $process->getOutput());
|
||||
}
|
||||
|
||||
public function testExitCodeText()
|
||||
{
|
||||
$process = $this->getProcess('');
|
||||
|
Reference in New Issue
Block a user