1 頁 (共 1 頁)

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

發表於 : 2008年 11月 27日, 14:00
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>"); 
      } 
    }