1--TEST-- 2Test popen() and pclose function: basic functionality 3 4--SKIPIF-- 5<?php 6if(substr(PHP_OS, 0, 3) != 'WIN' ) 7 die("skip Not Valid for Linux"); 8?> 9 10--FILE-- 11<?php 12/* 13 * Prototype: resource popen ( string command, string mode ) 14 * Description: Opens process file pointer. 15 16 * Prototype: int pclose ( resource handle ); 17 * Description: Closes process file pointer. 18 */ 19 20echo "*** Testing popen(): reading from the pipe ***\n"; 21 22$file_path = dirname(__FILE__); 23 24$string = "Sample String"; 25$file_handle = popen(" echo $string", "r"); 26fpassthru($file_handle); 27pclose($file_handle); 28 29echo "*** Testing popen(): writing to the pipe ***\n"; 30$arr = array("ggg", "ddd", "aaa", "sss"); 31// popen("sort", "w") fails if variables_order="GPCS" 32// this is set in the default INI file 33// it doesn't seem to be changeable in the --INI-- section 34// also, doing: ini_set('variables_order', ''); doesn't work! 35// 36// the only solution is to either put the absolute path here, or 37// remove variables_order= from PHP.ini (setting it in run-test's 38// default INI will fail too) 39// 40// since we can't depend on PHP.ini being set a certain way, 41// have to put the absolute path here. 42 43$sysroot = exec('echo %SYSTEMROOT%'); 44 45$file_handle = popen("$sysroot/system32/sort", "w"); 46$newline = "\n"; 47foreach($arr as $str) { 48 fwrite($file_handle, (binary)$str); 49 fwrite($file_handle, (binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)$newline); 50} 51pclose($file_handle); 52 53echo "*** Testing popen() and pclose(): return type ***\n"; 54$return_value_popen = popen("echo $string", "r"); 55fpassthru($return_value_popen); 56var_dump( is_resource($return_value_popen) ); 57$return_value_pclose = pclose($return_value_popen); 58var_dump( is_int($return_value_pclose) ); 59 60echo "\n--- Done ---"; 61?> 62--EXPECTF-- 63*** Testing popen(): reading from the pipe *** 64Sample String 65*** Testing popen(): writing to the pipe *** 66aaa 67ddd 68ggg 69sss 70*** Testing popen() and pclose(): return type *** 71Sample String 72bool(true) 73bool(true) 74 75--- Done --- 76