2011-12-15 40 views
1

我使用system() PHP函数来运行一些像这样的卷曲命令system("curl command here",$output);,但它在屏幕上显示结果。任何方式来避免这种输出?如何防止在浏览器中打印输出的system()函数?

+0

也许在它前面使用`@`? `@ system` – 2011-12-15 14:36:39

+0

你想要完成什么?根据你引用的文档,这是在PHP中使用`system()`(也就是执行一个命令和“_display the output_”)。是的,有办法解决这个问题,但是可能会有一个适合你的问题的更细粒度的方法,它不涉及`system()`。 – pilcrow 2011-12-15 14:39:24

回答

3

你尝试使用输出缓冲。

ob_start(); 
system("curl command here",$output); 
$result = ob_get_contents(); 
ob_end_clean(); 
1

你可以要么修改命令字符串和追加 “1>的/ dev/null的2> & 1” 或 - 更优雅 - 用pipe执行的处理(参见实施例#2)。

为了更好地控制流程的文件句柄,您还可以使用proc_open()

5

您正在使用错误的功能。根据文档:

system()就像函数的C版本一样,它执行给定的命令并输出结果。

所以它总是输出。使用exec­Docs代替它不会返回(而不是输出)的程序输出:

$last = exec("curl command here", $output, $status); 
$output = implode("\n", $output); 

或(只是为了完整性)使用output buffering­Docs

ob_start(); 
system("curl command here", $status); 
$output = ob_get_clean(); 
1

system功能显示从您的命令的输出,所以你那里运气不好。

你想要的是改变systemexec。该函数不会显示命令的输出。