通过配置文件在Java中运行系统命令

通过配置文件在Java中运行系统命令,java,cmd,Java,Cmd,如何通过相同的Java代码运行配置文件中的命令?我希望通过相同的Java代码运行命令行脚本;我可以在硬编码时运行它,但我想从配置文件运行这些命令,请告诉我怎么做 try { Runtime rt = Runtime.getRuntime(); Process pr = rt.exec("cmd /c dir"); Process pr = rt.exec("C:/bea/wlserver_10.3/server/bin/setWLSE

如何通过相同的Java代码运行配置文件中的命令?我希望通过相同的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配置文件中运行exec参数中的命令,我放在那里的命令将在xml配置文件中,我希望从那里运行这些命令。

您的老朋友
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) {}