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
