PHP shell_exec() vs exec()

Webnet picture Webnet · Aug 17, 2011 · Viewed 450.1k times · Source

I'm struggling to understand the difference between shell_exec() and exec()...

I've always used exec() to execute server side commands, when would I use shell_exec()?

Is shell_exec() just a shorthand for exec()? It seems to be the same thing with fewer parameters.

Answer

Daniel A. White picture Daniel A. White · Aug 17, 2011

shell_exec returns all of the output stream as a string. exec returns the last line of the output by default, but can provide all output as an array specifed as the second parameter.

See