How do PHP interact with the Shell Linux Dialog interface?

Asked

Viewed 94 times

1

How to interact the php7-cli with the interface Dialog Shell Linux, displaying values of variables on the screen?

1 answer

1


I decided as follows:

Prerequisites: php5-cli or higher.

# apt-get install dialog

php dialog.

<?php

$title   = 'Your title';
$message = 'Hello World!';

function dialog($args)
{
    $pipes  = array(NULL, NULL, NULL);
    $in     = fopen('php://stdin', 'r');
    $out    = fopen('php://stdout', 'w');
    $p      = proc_open('dialog ' . $args, array (0 => $in, 1 => $out, 2 => array ('pipe', 'w')), $pipes);
    $result = stream_get_contents($pipes[2]);

    fclose($pipes[2]);
    fclose($out);
    fclose($in);
    proc_close($p);

    return $result;
}

echo dialog("--no-shadow --title '" . $title . "' --msgbox '" . $message . "' 40 100");

To execute:

$ php dialog.php

Upshot:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.