2 Test popen() and pclose function: basic functionality
6 if(substr(PHP_OS, 0, 3) != 'WIN' )
7 die("skip Not Valid for Linux");
13 * Prototype: resource popen ( string command, string mode )
14 * Description: Opens process file pointer.
16 * Prototype: int pclose ( resource handle );
17 * Description: Closes process file pointer.
20 echo "*** Testing popen(): reading from the pipe ***\n";
22 $file_path = dirname(__FILE__);
24 $string = "Sample String";
25 $file_handle = popen(" echo $string", "r");
26 fpassthru($file_handle);
29 echo "*** 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!
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)
40 // since we can't depend on PHP.ini being set a certain way,
41 // have to put the absolute path here.
43 $sysroot = exec('echo %SYSTEMROOT%');
45 $file_handle = popen("$sysroot/system32/sort", "w");
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);
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) );
60 echo "\n--- Done ---";
63 *** Testing popen(): reading from the pipe ***
65 *** Testing popen(): writing to the pipe ***
70 *** Testing popen() and pclose(): return type ***