簡體   English   中英

通過配置文件在Java中運行系統命令

[英]Running system commands in Java through a config file

如何通過相同的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) {}

您也可以參考本教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM