Annotation of embedaddon/php/ext/standard/tests/file/popen_pclose_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test popen() and pclose function: basic functionality
3: --SKIPIF--
4: <?php
5: if(substr(PHP_OS, 0, 3) == 'WIN' )
6: die("skip Not Valid for Windows");
7: ?>
8:
9: --FILE--
10: <?php
11: /*
12: * Prototype: resource popen ( string command, string mode )
13: * Description: Opens process file pointer.
14: *
15: * Prototype: int pclose ( resource handle );
16: * Description: Closes process file pointer.
17: */
18:
19: $file_path = dirname(__FILE__);
20: require($file_path."/file.inc");
21:
22: echo "*** Testing popen() and pclose() with different processes ***\n";
23:
24: echo "-- Testing popen(): reading from the pipe --\n";
25: $dirpath = $file_path."/popen_basic";
26: mkdir($dirpath);
27: touch($dirpath."/popen_basic.tmp");
28: define('CMD', "ls $dirpath");
29: $file_handle = popen(CMD, 'r');
30: fpassthru($file_handle);
31: pclose($file_handle);
32:
33: echo "-- Testing popen(): reading from a file using 'cat' command --\n";
34: create_files($dirpath, 1, "text_with_new_line", 0755, 100, "w", "popen_basic", 1, "bytes");
35: $filename = $dirpath."/popen_basic1.tmp";
36: $command = "cat $filename";
37: $file_handle = popen($command, "r");
38: $return_value = fpassthru($file_handle);
39: echo "\n";
40: var_dump($return_value);
41: pclose($file_handle);
42: delete_files($dirpath, 1);
43:
44: echo "*** Testing popen(): writing to the pipe ***\n";
45: $arr = array("ggg", "ddd", "aaa", "sss");
46: $file_handle = popen("sort", "w");
47: $counter = 0;
48: $newline = "\n";
49: foreach($arr as $str) {
50: fwrite($file_handle, (binary)$str);
51: fwrite($file_handle, (binary)$newline);
52: }
53: pclose($file_handle);
54:
55:
56: echo "*** Testing for return type of popen() and pclose() functions ***\n";
57: $string = "Test String";
58: $return_value_popen = popen("echo $string", "r");
59: var_dump( is_resource($return_value_popen) );
60: fpassthru($return_value_popen);
61: $return_value_pclose = pclose($return_value_popen);
62: var_dump( is_int($return_value_pclose) );
63:
64: echo "\n--- Done ---";
65: ?>
66: --CLEAN--
67: <?php
68: $file_path = dirname(__FILE__);
69: $dirpath = $file_path."/popen_basic";
70: unlink($dirpath."/popen_basic.tmp");
71: unlink($dirpath."/popen_basic1.tmp");
72: rmdir($dirpath);
73: ?>
74:
75: --EXPECTF--
76: *** Testing popen() and pclose() with different processes ***
77: -- Testing popen(): reading from the pipe --
78: popen_basic.tmp
79: -- Testing popen(): reading from a file using 'cat' command --
80: line
81: line of text
82: line
83: line of text
84: line
85: line of text
86: line
87: line of text
88: line
89: line of text
90: line
91: line
92: int(100)
93: *** Testing popen(): writing to the pipe ***
94: aaa
95: ddd
96: ggg
97: sss
98: *** Testing for return type of popen() and pclose() functions ***
99: bool(true)
100: Test String
101: bool(true)
102:
103: --- Done ---
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>