PHP shell_exec() 及 system() 的分别


在 PHP shell_exec() 及 system 都可以执行外部指令, 使用上它们的分别主要来自回传及输出。

shell_exec(): 执行外部指令并回传执行结果, 但不会印出执行结果:

而执行 shell_exec() 另一种方法是用 “" 符号 (按住 Shift 再按 1 那个), 例如 ls -l` 跟 shell_exec(“ls -l”) 是一样的。

system(): 会执行外部指令并直接印出指令结果, 但如果指令有多行执行结果, 只会回传最后一行, 根据 PHP 官方的讲法:

Tags:

Leave a Reply