0
我想通过php执行一个shell命令并在浏览器中显示它。无论如何要这样做? 这里是我的PHP代码:[test.php的]通过php执行shell命令并将其显示在浏览器中?
<?php
$number=$_GET["num"];
$date=$_GET["date"];
$output = shell_exec('egrep -w '2012-09-01|974' /home/myquery_test/log/push.log');
echo "<pre>$output</pre>";
?>
当我运行这个(test.php的)文件从浏览器没有显示出来。但当我改变
$output = shell_exec('ls')
其工作正常!为什么egrep/grep命令不工作?
太棒了:)非常感谢! – sree127
嘿,$ output = shell_exec('tail -f | egrep“$ number。* $ date”/var/www/myquery_test/log/push.log')不起作用。是因为'|'吗?符号??任何选择? – sree127
@ user1640534这不是因为管道,这是因为单引号。 PHP不解析单引号的内容。我将为我的答案添加各种替代方案 –