O'Reilly logo

Sams Teach Yourself PHP in 24 Hours, Third Edition by Matt Zandstra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Opening Pipes to and from Processes with popen() and proc_open()

Just as you open a file for writing or reading with fopen(), you can open a pipe to a process with popen(). popen() requires the path to a command and a string representing a mode (read or write). It returns a file pointer that can be used similarly to the file pointer returned by fopen(). You can pass popen() one of two mode flags: "w" to write to the process and "r" to read from it. You cannot, however, both read and write to a process in the same connection.

When you have finished working with the file handle returned by popen(), you must close the connection by calling pclose(), which requires a valid file handler.

Reading from popen() is useful when you want to parse the output ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required