2014-05-11 2 views
0

동일한 Java 코드를 통해 구성 파일에있는 명령을 어떻게 실행합니까? 동일한 Java 코드를 통해 명령 줄 스크립트를 실행하고 싶습니다. 나는 그것을 하드 코드 할 때 실행할 수 있지만 설정 파일에서이 명령을 실행하고 싶다면 어떻게해야하는지 알려 주시기 바랍니다. 나는 XML 설정 파일에서 간부에 대한 인수에 명령을 실행하려면 어떻게구성 파일을 통해 Java에서 시스템 명령 실행

try { 
     Runtime rt = Runtime.getRuntime(); 
     Process pr = rt.exec("cmd /c dir"); 
     Process pr = rt.exec("C:/bea/wlserver_10.3/server/bin/setWLSEnv.cmd && java weblogic.Admin -url server:port -username system -password passwd CLUSTERSTATE -clusterName cluster"); 
     BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream())); 
     String line=null; 
     while((line=input.readLine()) != null) 
     { 
      System.out.println(line); 
      int exitVal = pr.waitFor(); 
      System.out.println("Exited with error code "+exitVal); 
     } 
}finally{ 
}}}} catch(Exception e) 

, 내가 거기에 넣어 봤어요 명령은 XML 설정 파일에있을거야, 나는 거기에서 이러한 명령을 TUN합니다.

답변

2

당신의 오랜 친구 Runtime.getRuntime.exec()

try { 
    String str ="C:/somefile.txt"; 
    Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c",str}); 
    System.out.println(str); 
    } catch (Exception ex) {} 

또한 this tutorial를 참조 할 수 있습니다.

+0

의견에 코드를 게시하지 마십시오. 질문에 게시하십시오. – unknown