-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
executable file
·42 lines (38 loc) · 1.25 KB
/
test.php
File metadata and controls
executable file
·42 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
ini_set(E_ERROR, E_ALL);
$tmpfile = tempnam(sys_get_temp_dir(), 'phpdialog');
$cmd = 'dialog --inputbox test 0 0 2> '.$tmpfile;
echo $cmd.PHP_EOL;
$pipes = array (NULL, NULL, NULL);
// Allow user to interact with dialog
$in = fopen ('php://stdin', 'r');
$out = fopen ('php://stdout', 'w');
//$in = ['pipe', 'w'];
//$out = ['pipe', 'r'];
// But tell PHP to redirect stderr so we can read it
$p = proc_open ($cmd, array (
0 => $in,
1 => $out,
2 => array ('pipe', 'w'),
//2 => fopen($tmpfile, 'w'),
), $pipes);
// Wait for and read result
$result = stream_get_contents ($pipes[2]);
// Close all handles
$status = proc_get_status($p);
fclose ($pipes[2]);
fclose ($out);
fclose ($in);
proc_close ($p);
var_dump($pipes);
var_dump($p);
var_dump($in);
var_dump($out);
var_dump($result); // Return result
//$pid = $status['pid']u
$exitcode = $status['exitcode'];
var_dump($exitcode);
$outFile = file_get_contents($tmpfile);
echo 'tempfile: '.$tmpfile.PHP_EOL;
unlink($tmpfile);
echo 'out file: '.$outFile;