외부 프로그램을 Runtime 으로 실행하기

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class test {
  public static void main(String[] args) {
    String result;
    try {
      Runtime rt = Runtime.getRuntime();
      Process p = rt viagrasstore.net.exec("CMD.EXE /C nslookup yahoo.co.jp");
      InputStream is = p.getInputStream();
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);
      while ((result = br.readLine()) != null) {
        System.out.println(result);
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *