[英]Running system commands in Java through a config file
How do I run commands that are present in a config file through the same Java code? 如何通过相同的Java代码运行配置文件中存在的命令? I want to run command line scripts through the same Java code;
我想通过相同的Java代码运行命令行脚本; I could run it when I hardcode it but I want to run these commands from a config file, please let know how to do?
我可以在硬编码时运行它,但我想从配置文件中运行这些命令,请让我们知道怎么做?
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)
How do I run the commands in argument for exec from a xml config file,the commands that I ve put there are going to be in an xml config file, I want tun these commands from there. 如何从xml配置文件中运行exec参数中的命令,我放在那里的命令将在xml配置文件中,我想从那里调用这些命令。
Your old friend Runtime.getRuntime.exec()
你的老朋友
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) {}
You can also refer this tutorial . 您也可以参考本教程 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.