[英]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.