글보기
JAVA,JSP 에서 쉘명령어 실행 및 결과 보여주기 예제(Runtime)

<%@ 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>



아래는 관련 댓글들입니다.   댓글수: 0

앨범방 문의전화
010-2358-5700
평일 오전10시 ~ 오후5시
앨범방 계좌번호
하나은행
659-910429-20707
예금주 조우성
신용카드결제
안전한 나이스페이 전자결제시스템을 사용하고 있습니다.
이상 무료배송
주문하시는 총상품금액의 합계가 이상일 경우 택배비()가 무료입니다.
안전거래가맹점