dpquu9206 2011-09-29 01:35 采纳率: 0%
浏览 332
已采纳

PHP上的shell_exec和exec没有返回字符串

I got headache by this code:

$data = shell_exec("wget -S --spider http://dkphp.com");
echo "Encoded:" .$data;

$data is "NULL"

I don't know why, its support to echo something like :( Spend like 5 hours today, and its still NULL :(

HTTP request sent, awaiting response...
  HTTP/1.0 200 OK
  Date: Thu, 29 Sep 2011 01:31:45 GMT
  Server: LiteSpeed
  Connection: close
  X-Powered-By: PHP/5.3.8
  Set-Cookie: PHPSESSID=50781d657c7632cc1b2e7536d5fa0c50; path=/
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
  Cache-Control: no-store, no-cache, must-revalidate, post-check=0,
  Pragma: no-cache
  content: text/html
  Content-Type: text/html
Length: unspecified [text/html]
200 OK
  • 写回答

1条回答

  • douh9817 2011-09-29 01:40
    关注

    I checked your code snippet in PHP's interactive mode (php -a from the command line)

    wget prints that information to STDERR, not STDOUT.

    This works:

    $data = shell_exec("wget -S --spider http://dkphp.com 2>&1");
    echo "Encoded:" .$data;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误