[PHP]利用 pipe 來顯示執行 command 的結果

有關網頁及相關語法的討論
回覆文章
頭像
tim
文章: 1380
註冊時間: 2008年 11月 26日, 00:49

[PHP]利用 pipe 來顯示執行 command 的結果

文章 tim »

利用 pipe open 的方式, 執行外部指令, 使用函式 : popen() !!
輸出時, 利用 htmlentities 將可能為 html 的碼編為不會衝突可
顯示的 html!!

代碼: 選擇全部

     
    function rumcmd($scmd) 
    { 
      if($scmd != "")  
      { 
        print(" running..... $scmd "); 
        print("<PRE>"); 
        if($oStream = popen("$scmd","r"))     
          while ( !feof($oStream)) 
          { 
            $sread = fgets($oStream, 1024); 
            print( htmlentities($sread) );     
          }     
        else     
          print("error run $scmd!!"); 
        print("</PRE>"); 
      } 
    }  
多多留言, 整理文章, 把經驗累積下來.....
回覆文章