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
10echo "*** Testing popen(): reading from the pipe ***\n";
11
12$file_path = __DIR__;
13
14$string = "Sample String";
15$file_handle = popen(" echo $string", "r");
16fpassthru($file_handle);
17pclose($file_handle);
18
19echo "*** Testing popen(): writing to the pipe ***\n";
20$arr = array("ggg", "ddd", "aaa", "sss");
21// popen("sort", "w") fails if variables_order="GPCS"
22// this is set in the default INI file
23// it doesn't seem to be changeable in the--INI-- section
24//	also, doing: ini_set('variables_order', ''); doesn't work!
25//
26// the only solution is to either put the absolute path here, or
27// remove variables_order= from PHP.ini (setting it in run-test's
28// default INI will fail too)
29//
30// since we can't depend on PHP.ini being set a certain way,
31// have to put the absolute path here.
32
33$sysroot = exec('echo %SYSTEMROOT%');
34
35$file_handle = popen("$sysroot/system32/sort", "w");
36$newline = "\n";
37foreach($arr as $str) {
38  fwrite($file_handle, (binary)$str);
39  fwrite($file_handle, (binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)$newline);
40}
41pclose($file_handle);
42
43echo "*** Testing popen() and pclose(): return type ***\n";
44$return_value_popen = popen("echo $string", "r");
45fpassthru($return_value_popen);
46var_dump( is_resource($return_value_popen) );
47$return_value_pclose = pclose($return_value_popen);
48var_dump( is_int($return_value_pclose) );
49
50echo "\n--- Done ---";
51?>
52--EXPECT--
53*** Testing popen(): reading from the pipe ***
54Sample String
55*** Testing popen(): writing to the pipe ***
56aaa
57ddd
58ggg
59sss
60*** Testing popen() and pclose(): return type ***
61Sample String
62bool(true)
63bool(true)
64
65--- Done ---
66