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.
The exec() function is an inbuilt function in PHP which is used to execute an external program and returns the last line of the output. It also returns NULL if no command run properly. Syntax: string exec( $command, $output, $return_var )
Updated: 05/04/2019 by Computer Hope. On Unix-like operating systems, exec is a builtin command of the Bash shell. It lets you execute a command that completely replaces the current process. The current shell process is destroyed, and entirely replaced by the command you specify.
You can execute linux commands within a php script - all you have to do is put the command line in brackits (`). And also concentrate on exec() , this and shell_exec() ..
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With