我创建了一个java应用程序,它使用函数调用运行两个.cmd文件,并调用其他一些函数。但运行.cmd文件后执行停止,没有任何错误。如果我评论运行函数调用的.cmd文件并运行程序,其他代码行将被执行。请帮助解决此问题。我希望程序运行到最后。
粘贴我的一些代码[不完整的代码]。两个.cmd文件通过rename()和removepwd()函数执行。鉴于两个功能代码也。 请帮助完全一次性运行该程序。
public class DashboardClass {
public static void main(String args[]) {
DashboardService dashboardservice = new DashboardService(); //Object for class DashboardService
String filelocation = "C:\\Users\\Sample";
dashboardservice.rename(); //To run rename script - Code given below
dashboardservice.removepwd(); //To run remove password script - code given below
// ***************执行在此处停止***************
List<HashMap> list = new ArrayList<HashMap>();
list = DashboardService.CSVToMap();
Map<String, String> BAprodmap = list.get(0);
Map<String, String> BAtestmap = list.get(1);
/*
converter function to convert csv to excel
insertcolumn function to add company name
*/
dashboardservice.converter(filelocation + "sample.csv");
..............
..............
..............
}
}
=============================================== ==============
public void rename() {
Runtime run = Runtime.getRuntime();
Process p = null;
String cmd = "rename.cmd";
try {
p = run.exec(cmd);
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
p.getOutputStream();
System.out.println("success");
}
catch (IOException e) {
e.printStackTrace();
System.out.println("ERROR.RUNNING.CMD");
}
finally{
p.destroy();
}
}
=============================================== ============================ // FUNCTION TO RUN removepasswords.cmd
public void removepwd() {
Process proc = null;
Runtime rt = Runtime.getRuntime();
String cmd1 = "RemovePasswords.cmd";
try {
proc = rt.exec(cmd1);
InputStream outCmdStream = proc.getInputStream();
InputStreamReader outCmdReader = new InputStreamReader(outCmdStream);
BufferedReader outCmdBufReader = new BufferedReader(outCmdReader);
String outLine;
while ((outLine = outCmdBufReader.readLine()) != null) {
System.out.println(outLine);
}
InputStream errStream = proc.getErrorStream();
InputStreamReader errReader = new InputStreamReader(errStream);
BufferedReader errBufReader = new BufferedReader(errReader);
String errLine;
while ((errLine = errBufReader.readLine()) != null) {
System.out.println(errLine);
}
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
System.out.println("success");
} catch (IOException | InterruptedException e) {
e.printStackTrace();
System.out.println("ERROR.RUNNING.CMD");
proc.destroy();
}
}