http://madnix.tistory.com/m/post/entry/Java에서-Linux-Shell-명령어-실행하기
import java.io.BufferedReader;
}
<%@ 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>
'java' 카테고리의 다른 글
Runtime 에 jar 파일 클래스패스에 추가 시키기 : RuntimeJarLoader (0) | 2013.09.03 |
---|---|
XMLEncoder, XMLDecoder 서블릿 사용 예제(HttpConnection 이용) (0) | 2013.05.24 |
Java 실행 옵션 정리 (0) | 2013.01.31 |
java.sql.Date <==> java.util.Date (0) | 2013.01.31 |
파일 저장시 특정 캐릭터셋으로 저장하기 (0) | 2013.01.31 |