http://choiseyoung.tistory.com/281
이것을 참조했다.
java클래스로 만든 소스를 올린다.
package jxe.console;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Console {
public static String runCommand(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String lineStr = null;
StringBuffer sb = null;
sb = new StringBuffer();
while ((lineStr = br.readLine()) != null) {
sb.append(lineStr);
sb.append("
");
}
br.close();
return sb.toString();
} catch (IOException ie) {
System.err.println("runCommand - error : " + ie.toString());
return "runCommand - error : " + ie.toString();
}
}
public static boolean isReturnResult(String command, String strResult) {
if (runCommand(command).contains(strResult)) {
return true;
} else {
return false;
}
}
}
위의 함수는 커맨드를 돌리기만 하는것
아래 함수는 커맨드의 결과에 어떤 문자열이 있는지 확인하는 것이다.
혹 나처럼 귀찮은 사람이 있을까 해서 올린다
댓글 없음:
댓글 쓰기