dpquu9206
2011-09-29 01:35
浏览 283
已采纳

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

图片转代码服务由CSDN问答提供 功能建议

我对此代码感到头疼:

  $ data =  shell_exec(“wget -S --spider http://dkphp.com”); 
echo“编码:”。$ data; 
   
 
 

$ data is“ NULL“

我不知道为什么,它支持回声类似:(今天花了5个小时,它仍然是NULL :(

 发送HTTP请求,等待响应... 
 HTTP / 1.0 200 OK 
日期:星期四,2011年9月29日01:31:45 GMT 
服务器:LiteSpeed 
连接:关闭
 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;
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题