How to interact with php7-cli with the Dialog interface of Shell Linux, displaying values of variables on the screen?
How to interact with php7-cli with the Dialog interface of Shell Linux, displaying values of variables on the screen?
I have decided as follows:
Prerequisites: php5-cli or higher.
# apt-get install dialog
dialog.php
<?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 run:
$ php dialog.php
Result: