9.6. Shell Commands

This section describes functions that interact with the command shell in some way. Some of them execute other programs, and two of them read or write to environment variables.

string exec(string command, array output, integer return)

The exec function (Listing 9.94) attempts to execute the command argument as if you had typed it in the command shell. PHP sends nothing to the browser but returns the last line of output from the execution. If you supply the optional output argument, PHP adds each line of output to the output argument. If you supply the optional return argument, PHP sets it with the command's return value.

It is very dangerous to put any user-supplied information inside the command argument. Users may pass values ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.