我一直试图让这个shell_exec()命令在我的PHP脚本中运行,但它一直没有返回任何结果。我已经从命令行成功地运行了它,并得到了预期的结果。
有人能帮忙调试吗?
$cmd ="/bin/grep '"John Smith'" -oPr --include='"*.txt'" --exclude='"title.txt'"|/usr/bin/sort|/usr/bin/uniq -c";
$rs = exec($cmd);
echo "Command: $cmd<br/>";
echo "[$rs]<br/>";
非常感谢!
exec()
由于服务器上的安全原因而被禁用当PHP在安全模式下运行时,此函数将被禁用。
要在php中启用exec()
,
如果你在wamp服务器上工作
停止wamp服务器打开php.ini
文件检查禁用功能注释disable_functions,只需在disable_functions之前添加分号(;)
如下图所示
; disable_functions = glob, filter_list, chown, chmod, get_current_user, php_uname, putenv, getmyuid, getmypid, dl, ini_alter, ini_restore, exec, passthru, system, popen, pclose, leak, mysql_list_dbs, listen, chgrp, disk_total_space, disk_free_space, rmdir, tmpfile, link, shell_exec, proc_open, chroot, openlog, closelog, syslog, flock, socket_create_listen, socket_accept, socket_listen, sleep, umask, set_include_path, restore_include_path, symlink, imagerotate
保存文件和立即重新启动wamp服务器然后再试一次。
更换
--exclude='"title.txt'"|
通过
--exclude='"title.txt'" <DIRECTORY_TO_SEARCH> |