Return to popen_pclose_basic-win32.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test popen() and pclose function: basic functionality 3: 4: --SKIPIF-- 5: <?php 6: if(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: 20: echo "*** 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"); 26: fpassthru($file_handle); 27: pclose($file_handle); 28: 29: echo "*** Testing popen(): writing to the pipe ***\n"; 30: $arr = array("ggg", "ddd", "aaa", "sss"); 1.1.1.2 misho 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. 1.1.1.3 ! misho 42: ! 43: $sysroot = exec('echo %SYSTEMROOT%'); ! 44: ! 45: $file_handle = popen("$sysroot/system32/sort", "w"); 1.1 misho 46: $newline = "\n"; 47: foreach($arr as $str) { 48: fwrite($file_handle, (binary)$str); 49: fwrite($file_handle, (binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)$newline); 50: } 51: pclose($file_handle); 52: 53: echo "*** Testing popen() and pclose(): return type ***\n"; 54: $return_value_popen = popen("echo $string", "r"); 55: fpassthru($return_value_popen); 56: var_dump( is_resource($return_value_popen) ); 57: $return_value_pclose = pclose($return_value_popen); 58: var_dump( is_int($return_value_pclose) ); 59: 60: echo "\n--- Done ---"; 61: ?> 62: --EXPECTF-- 63: *** Testing popen(): reading from the pipe *** 64: Sample String 65: *** Testing popen(): writing to the pipe *** 66: aaa 67: ddd 68: ggg 69: sss 70: *** Testing popen() and pclose(): return type *** 71: Sample String 72: bool(true) 73: bool(true) 74: 75: --- Done ---