1--TEST--
2Redirection support in proc_open
3--FILE--
4<?php
5
6$php = getenv('TEST_PHP_EXECUTABLE');
7var_dump(proc_open([$php], [['redirect']], $pipes));
8var_dump(proc_open([$php], [['redirect', 'foo']], $pipes));
9var_dump(proc_open([$php], [['redirect', 42]], $pipes));
10
11echo "\nWith pipe:\n";
12$cmd = [$php, '-r', 'echo "Test\n"; fprintf(STDERR, "Error");'];
13$proc = proc_open($cmd, [1 => ['pipe', 'w'], 2 => ['redirect', 1]], $pipes);
14var_dump($pipes);
15var_dump(stream_get_contents($pipes[1]));
16proc_close($proc);
17
18echo "\nWith filename:\n";
19$fileName = __DIR__ . '/proc_open_redirect.txt';
20$proc = proc_open($cmd, [1 => ['file', $fileName, 'w'], 2 => ['redirect', 1]], $pipes);
21var_dump($pipes);
22proc_close($proc);
23var_dump(file_get_contents($fileName));
24unlink($fileName);
25
26echo "\nWith file:\n";
27$file = fopen($fileName, 'w');
28$proc = proc_open($cmd, [1 => $file, 2 => ['redirect', 1]], $pipes);
29var_dump($pipes);
30proc_close($proc);
31fclose($file);
32var_dump(file_get_contents($fileName));
33unlink($fileName);
34
35echo "\nWith inherited stdout:\n";
36$proc = proc_open($cmd, [2 => ['redirect', 1]], $pipes);
37proc_close($proc);
38
39?>
40--EXPECTF--
41Warning: proc_open(): Missing redirection target in %s on line %d
42bool(false)
43
44Warning: proc_open(): Redirection target must be an integer in %s on line %d
45bool(false)
46
47Warning: proc_open(): Redirection target 42 not found in %s on line %d
48bool(false)
49
50With pipe:
51array(1) {
52  [1]=>
53  resource(4) of type (stream)
54}
55string(10) "Test
56Error"
57
58With filename:
59array(0) {
60}
61string(10) "Test
62Error"
63
64With file:
65array(0) {
66}
67string(10) "Test
68Error"
69
70With inherited stdout:
71Test
72Error
73