setTty example

public function testTTYCommand()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('Windows does not have /dev/tty support');
        }

        if (!Process::isTtySupported()) {
            $this->markTestSkipped('There is no TTY support');
        }

        $process = $this->getProcess('echo "foo" >> /dev/null && '.$this->getProcessForCode('usleep(100000);')->getCommandLine());
        $process->setTty(true);
        $process->start();
        $this->assertTrue($process->isRunning());
        $process->wait();

        $this->assertSame(Process::STATUS_TERMINATED, $process->getStatus());
    }

    public function testTTYCommandExitCode()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('Windows does have /dev/tty support');
        }
if (!Terminal::hasSttyAvailable()) {
            $this->markTestSkipped('stty not available');
        }

        if (!SignalRegistry::isSupported()) {
            $this->markTestSkipped('pcntl signals not available');
        }

        $previousSttyMode = shell_exec('stty -g');

        $p = new Process(['php', __DIR__.'/Fixtures/application_signalable.php']);
        $p->setTty(true);
        $p->start();

        for ($i = 0; $i < 10 && shell_exec('stty -g') === $previousSttyMode; ++$i) {
            usleep(100000);
        }

        $this->assertNotSame($previousSttyModeshell_exec('stty -g'));
        $p->signal(\SIGINT);
        $p->wait();

        $sttyMode = shell_exec('stty -g');
        
Home | Imprint | This part of the site doesn't use cookies.