Annotation of embedaddon/php/ext/standard/tests/file/popen_pclose_basic-win32.phpt, revision 1.1.1.2

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.
        !            42: $file_handle = popen("/windows/system32/sort", "w");
1.1       misho      43: $newline = "\n";
                     44: foreach($arr as $str) {
                     45:   fwrite($file_handle, (binary)$str);
                     46:   fwrite($file_handle, (binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)(binary)$newline);
                     47: }
                     48: pclose($file_handle);
                     49: 
                     50: echo "*** Testing popen() and pclose(): return type ***\n";
                     51: $return_value_popen = popen("echo $string", "r");
                     52: fpassthru($return_value_popen);
                     53: var_dump( is_resource($return_value_popen) );
                     54: $return_value_pclose = pclose($return_value_popen);
                     55: var_dump( is_int($return_value_pclose) );
                     56: 
                     57: echo "\n--- Done ---";
                     58: ?>
                     59: --EXPECTF--
                     60: *** Testing popen(): reading from the pipe ***
                     61: Sample String
                     62: *** Testing popen(): writing to the pipe ***
                     63: aaa
                     64: ddd
                     65: ggg
                     66: sss
                     67: *** Testing popen() and pclose(): return type ***
                     68: Sample String
                     69: bool(true)
                     70: bool(true)
                     71: 
                     72: --- Done ---

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>