GGYU

프로세스 실행 및 결과 확인 본문

프로그래밍/JAVA

프로세스 실행 및 결과 확인

GANADARA 2019. 5. 19. 16:02

String addr = "http://www.naver.com";
Process process = null;

String[] cmd = new String[] {"rundll32", "url.dll", "FileProtocolHandler", addr};
String str = null;

//String[] cmd = new String[] {"cmd", "dir", "/w"};Process process = new ProcessBuilder(cmd).start();
try {
  
    // 프로세스 빌더를 통하여 외부 프로그램 실행
    process = new ProcessBuilder(cmd).start();

    // 외부 프로그램의 표준출력 상태 버퍼에 저장
    BufferedReader stdOut = new BufferedReader( new InputStreamReader(process.getInputStream()) );
    
    // 표준출력 상태를 출력
    while( (str = stdOut.readLine()) != null ) {
        System.out.println(str);
    }
    
} catch (IOException e) {
    e.printStackTrace();

}

출처: https://yangyag.tistory.com/55 [Hello Brother!]

'프로그래밍 > JAVA' 카테고리의 다른 글

test  (0) 2020.05.06
Java Lib(C8)  (0) 2020.05.06
숫자체크  (0) 2019.04.21
시저암호화  (0) 2019.04.21
console 입력  (0) 2019.04.21
Comments