在命令后面加上
2>&1
例如;
system("ls -al 2>&1 ");
其显示信息会在浏览器中输出。
官网:
This is for WINDOWS users. I am running apache and I have been trying for hours now to capture the output of a command.
I’d tried everything that is written here and then continued searching online with no luck at all. The output of the command was never captured. All I got was an empty array.
Finally, I found a comment in a blog by a certain amazing guy that solved my problems.
Adding the string ’ 2>&1’ to the command name finally returned the output!! This works in exec() as well as system() in PHP since it uses stream redirection to redirect the output to the correct place!
system(“yourCommandName 2>&1”,$output) ;