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