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