downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

popen> <pathinfo
[edit] Last updated: Fri, 24 May 2013

view this page in

pclose

(PHP 4, PHP 5)

pcloseCierra un proceso de un puntero a un archivo

Descripción

int pclose ( resource $handle )

Cierra un puntero a un archvio hacia una tubería abierta por popen().

Parámetros

handle

El puntero al archivo debe ser válido, y debe haber sido devuelto por una llamada exitosa a popen().

Valores devueltos

Devuelve el estado de terminación del proceso que se estaba ejecutando. En caso de error, se devuelve -1.

Ejemplos

Ejemplo #1 Ejemplo de pclose()

<?php
$gestor 
popen('/bin/ls''r');
pclose($gestor);
?>

Notas

Nota: Solamente Unix:

proc_close() está internamente implementada usando la llamada al sistema de waitpid(3). Para obtener el código de estado de salida real debería usarse la función pcntl_wexitstatus().

Ver también

  • popen() - Abre un proceso de un puntero a un archivo



popen> <pathinfo
[edit] Last updated: Fri, 24 May 2013
 
add a note add a note User Contributed Notes pclose - [5 notes]
up
1
Mike
5 years ago
The termination status, as pointed out in another note, is not the same as the exit status from the process. However, something like "pclose($fp)/256" is not the correct way to extract the exit status, since this uses system- and version-specific knowledge of where in the termination status the exit status is stored. (Also, the process may not even have exited normally, so it may not have an exit status at all.)

Instead, the functions pcntl_wifexited() and pcntl_wexitstatus() should be used. They are wrappers for the C macros WIFEXITED() and WEXITSTATUS() that are designed for determining whether the process had an exit status and what that status was, respectively.
up
0
chad 0x40 herballure 0x2e com
5 years ago
Warning: If you're reading a command with infinite output, such as 'vmstat 2', pclose will cause the script to hang. This is because pclose waits for the command to exit, in order to return the exit status. If the process never exits, pclose never returns.
up
0
kcross at nssolutions dot com
9 years ago
Somewhere between 4.1.1 and 4.2.3, the return value from pclose changed.

The exit status used to be in the second byte, so that the status would be (pclose($fp)/256).

It is now in the low-order byte, so the status is just pclose($fp).

Be careful.
up
0
vdweij at mailsurf dot com
10 years ago
As I understand pclose will return 0 (on every platform) in case popen could not execute the specified command.

Since popen only returns the status wether it was able to send a command and not wether it was succesfully executed. Only the returned value of pclose can be used to check wether a command could be executed.
up
-1
roel at bouwman dot net
13 years ago
The return value of pclose() is not the exit status of the program, but a value as returned by waitpid() of wait4().

To obtain the exit status:

$ret=(pclose($f)>>8)&0xFF;

 
show source | credits | sitemap | contact | advertising | mirror sites