Skip to Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

21.21 Den Standardfehlerkanal eines Programms einlesen

Problem

Sie wollen die Fehlerausgabe eines Programms auslesen; zum Beispiel wollen Sie die Systemaufrufe, die von strace(1) angezeigt werden, einsehen.

Lösung

Leiten Sie den Standardfehlerkanal zur Standardausgabe um, indem Sie 2>&1 an die Kommandozeile, die an popen() durchgegeben wird, anfügen. Lesen Sie die Standardausgabe aus, indem Sie die Pipeline im r-Modus öffnen:

$ph = popen('strace ls 2>&1','r') or die($php_errormsg);
while (!feof($ph)) {
    $s = fgets($ph,1048576)       or die($php_errormsg);
}
pclose($ph)                       or die($php_errormsg);

Diskussion

Sowohl in der sh unter Unix als auch in der Windows-Shell cmd.exe ist der Standardfehlerkanal der Datei-Deskriptor 2 und die Standardausgabe der Datei-Deskriptor ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi

Publisher Resources

ISBN: 9783868993271Purchase book