like func("rm -rf /usr/local/)
Which 'func' will you use to do that?
like func("rm -rf /usr/local/)
Which 'func' will you use to do that?
You would use PHP's exec
function. Other options include system
, passthru
, and the backtick operator.
Personally I think proc_open is the best approach.
This gives you far more control over input, output and let's you check it's exit status and STDOUT, which is more than most other commands for system calls. It also doesn't hold up the system while the command exits.
It depends on what you want to obtain.
If you want to display the ouput of the command that has been executed, passthru
does the trick :
This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser. A common use for this is to execute something like the pbmplus utilities that can output an image stream directly.
If you want to get the output of the command in a variable as a whole string, you can use shell_exec
(which is the same as using the backtick operator) :
Execute command via shell and return the complete output as a string
And, if you want to get it line by line, you'll use exec
:
If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array.
And, finally, if you need a bit more control, you'll use proc_open
-- see the documentation, about that one ; it's a bit more tricky, I guess.
Still, when using those :
safe_mode_exec_dir
, about thatSo, I'd use those only when it is really necessary.