Skip to content

[Process] Disable TTY mode on Windows platform #10763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2014
Merged
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
6 changes: 6 additions & 0 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,15 @@ public function setTimeout($timeout)
* @param bool $tty True to enabled and false to disable
*
* @return self The current Process instance
*
* @throws RuntimeException In case the TTY mode is not supported
*/
public function setTty($tty)
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && $tty) {
throw new RuntimeException('TTY mode is not supported on Windows platform.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a LogicException rather than a RuntimeException IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been hesitating but I chose RuntimeException because we're already using this one in case Process::signal is called whereas the PHP has been compiled with --enable-sigchild

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is an error of logic in this case, it's just the platform does not support it

}

$this->tty = (bool) $tty;

return $this;
Expand Down
16 changes: 14 additions & 2 deletions src/Symfony/Component/Process/Tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function testTTYCommand()
}

$process = $this->getProcess('echo "foo" >> /dev/null && php -r "usleep(100000);"');
$process->setTTY(true);
$process->setTty(true);
$process->start();
$this->assertTrue($process->isRunning());
$process->wait();
Expand All @@ -266,12 +266,24 @@ public function testTTYCommandExitCode()
}

$process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTTY(true);
$process->setTty(true);
$process->run();

$this->assertTrue($process->isSuccessful());
}

public function testTTYInWindowsEnvironment()
{
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('This test is for Windows platform only');
}

$process = $this->getProcess('echo "foo" >> /dev/null');
$process->setTty(false);
$this->setExpectedException('Symfony\Component\Process\Exception\RuntimeException', 'TTY mode is not supported on Windows platform.');
$process->setTty(true);
}

public function testExitCodeTextIsNullWhenExitCodeIsNull()
{
$process = $this->getProcess('');
Expand Down