PHP Doku:: Schließt einen Prozess-Dateizeiger - function.pclose.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDateisystemrelevante ErweiterungenDateisystemDateisystem-Funktionenpclose

Ein Service von Reinhard Neidl - Webprogrammierung.

Dateisystem-Funktionen

<<pathinfo

popen>>

pclose

(PHP 4, PHP 5)

pcloseSchließt einen Prozess-Dateizeiger

Beschreibung

int pclose ( resource $handle )

Schließt einen Prozess-Dateizeiger, der durch einen Aufruf von popen() geöffnet wurde.

Der Dateizeiger muss gültig sein und durch einen erfolgreichen Funktionsaufruf von popen() zurückgegeben worden sein.

Gibt den End-Status eines laufenden Prozesses zurück.

Siehe auch popen().


5 BenutzerBeiträge:
- Beiträge aktualisieren...
Mike
7.04.2008 8:55
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.
chad 0x40 herballure 0x2e com
4.09.2007 22:16
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.
kcross at nssolutions dot com
16.07.2003 23:08
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.
vdweij at mailsurf dot com
12.03.2003 16:18
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.
roel at bouwman dot net
7.10.1999 19:23
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;



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)