xref: /PHP-7.4/ext/standard/tests/file/bug69442.phpt (revision d679f022)
1--TEST--
2proc_open with PTY closes incorrect file descriptor
3--SKIPIF--
4<?php
5
6$code = <<< 'EOC'
7    <?php
8    $descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
9    $pipes = array();
10    $process = proc_open('echo "foo";', $descriptors, $pipes);
11EOC;
12
13    $tmpFile = tempnam(sys_get_temp_dir(), "bug69442");
14    file_put_contents($tmpFile, $code);
15
16    exec($_SERVER['TEST_PHP_EXECUTABLE']." -d display_errors=1 -d error_reporting=E_ALL ".$tmpFile." 2>&1", $output);
17    $output = join("\n", $output);
18    unlink($tmpFile);
19
20    if (strstr($output, "pty pseudo terminal not supported on this system") !== false) {
21        die("skip PTY pseudo terminals are not supported");
22    }
23--FILE--
24<?php
25$cmd = '(echo "foo" ; exit 42;) 3>/dev/null; code=$?; echo $code >&3; exit $code';
26$descriptors = array(array("pty"), array("pty"), array("pty"), array("pipe", "w"));
27$pipes = array();
28
29$process = proc_open($cmd, $descriptors, $pipes);
30
31foreach ($pipes as $type => $pipe) {
32    $data = fread($pipe, 999);
33    echo 'type ' . $type . ' ';
34    var_dump($data);
35    fclose($pipe);
36}
37proc_close($process);
38--EXPECT--
39type 0 string(5) "foo
40"
41type 1 string(0) ""
42type 2 string(0) ""
43type 3 string(3) "42
44"
45