0

这个小问题已经让我忙了几天了。

我有一个执行命令的 PHP system() 命令,如下例所示:

echo '<p>';
system (escapeshellcmd("uname -a"));
echo '</p>';

输出打印到 PHP 页面,但我想限制或自动换行打印行的宽度,并防止命令在页面边界之外打印结果(宽度为 500 像素)。

我一定会使用系统(escapeschellcmd());所以我正在寻找一个包含这个命令的解决方案。

我什至找不到解决方案的提示...

彼得

4

1 回答 1

1

According to the manual entry for system, you can pass a variable as the command's second argument to save the output to that variable. Like so:

system (escapeshellcmd("uname -a"), $string);

Then you can do whatever you want with the resulting string at your leisure.

Update: that's not entirely correct. The second parameter is merely the return value. The command itself returns only the last line of the console output.

If you want the raw command line output (all of it), you will have to use passthru() instead of system().

于 2013-05-18T10:23:09.040 回答