내장바구니 | 주문배송조회 | 내적립금
6만원 이상 무료배송
주문하시는
총상품금액의 합계가
6만원 이상일 경우
택배비가 무료입니다.
JAVA,JSP 에서 쉘명령어 실행 및 결과 보여주기 예제(Runtime)
작성자: 어라    작성일: 2009-07-07 09:29   조회: 23073   댓글: 0
<%@ page language="java"
   import= "java.io.*, 
   java.util.*" 
   contentType="text/html;charset=EUC-KR" session="false" 
%>

<html>
<%

    String command = "ls -al";  // <---- 실행할 쉘명령어
    int lineCount = 0;
    String line="";

    Runtime rt = Runtime.getRuntime();
    Process ps = null;

    try{
      ps = rt.exec(command);

      BufferedReader br =
            new BufferedReader(

                    new InputStreamReader(

                          new SequenceInputStream(ps.getInputStream(), ps.getErrorStream())));

            

      while((line = br.readLine()) != null){
%>
    <%=line%><br> <!-- 결과 화면에 뿌리기... -->
<%
      }
      br.close();

   }catch(IOException ie){
      ie.printStackTrace();
   }catch(Exception e){
      e.printStackTrace();
   }
%>
</html>


 * 관련 댓글 한말씀 부탁합니다.
  작성자:    비밀번호:   (비밀번호는 숫자 4자리이며 본인댓글 삭제시 필요합니다.)
이용약관 | 개인정보취급방침