pclose()关闭由popen()函数打开的管道。必须使用pclose()关闭由popen()函数启动的文件指针。 popen()函数指定的管道作为参数发送给pclose()函数,它返回已运行进程的终止状态,或者在出现错误时返回-1。
null
语法:
pclose(pipe)
使用的参数: PHP中的pclose()函数只接受一个参数。
- 管道: 它是一个强制参数,用于指定popen()函数打开的管道。
返回值: 它返回已运行进程的终止状态,如果出现错误,则返回-1。
错误和例外:
- 要获取真正的退出状态代码 pcntl_wexitstatus() 应该使用函数。
- pclose()在每个平台上返回0,以防popen()无法执行指定的命令。
例如:
Input : $my_file = popen("/bin/ls", "r"); pclose($my_file); Output : 1 Input : $my_file = popen('/executable/gfg.exe', 'r'); echo "'my_file'; " . get_class($my_file) . ""; $file_read = fread($my_file, 4192); echo $file_read; pclose($my_file); Output : 1
下面的程序演示了pclose()函数。
方案1
<?php // opening a pipe $my_file = popen( "/bin/ls" , "r" ); // closing the my_file pclose( $my_file ); ?> |
输出:
1
方案2
<?php // opening a pipe $my_file = popen( '/executable/gfg.exe' , 'r' ); // returning name of class of an object using get_class() echo "'$my_file'; " . get_class( $my_file ) . "" ; // reading file using fread() $filereader = fread ( $my_file , 4192); echo $filereader ; // closing the pipe pclose( $my_file ); ?> |
输出:
1
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END