以下是我打算做的事情:
我已编写代码,如下所示。
import java.io.*;
import java.util.Arrays;
public class Testing {
static Boolean flag = true;
public static void main (String[] args) {
ProcessBuilder pb = new ProcessBuilder("C:/Users/narangh/Desktop/Desktop Shortcuts/Testing.bat");
Process process = null;
try {
process = pb.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
final InputStream is = process.getInputStream();
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
new Thread(new Runnable() {
public void run() {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
if(line.equalsIgnoreCase("[INFO] BUILD SUCCESSFUL")) {
System.out.println("Line found");
flag = true;
if(flag) {
ProcessBuilder startWeblogic = new ProcessBuilder("C:/bea/10.3/user_projects/domains/dev/bin/startWebLogic.cmd");
Process process1 = null;
try {
process1 = startWeblogic.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
else if(line.equalsIgnoreCase("BUILD FAILED"))
{
System.out.println("SERVER COULDN'T BE STARTED");
flag = false;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
// the outer thread waits for the process to finish
try {
process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
此代码的输出如下:
*Some Text Here*
[INFO] BUILD SUCCESSFUL
Line found
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Fri Nov 07 15:56:15 IST 2014
[INFO] Final Memory: 48M/702M
但是在成功的情况下它不会执行第二个过程。我在这段代码中错过了什么? 任何形式的帮助都会很棒。
谢谢, Hemika。
答案 0 :(得分:0)
我尝试过你用以下变化编写的程序: 1.在底部添加了缺失} 2.更改批处理文件名以反映我拥有的批处理文件。 该程序工作,它无法要求weblogic.bat这是所需的行为? 有什么问题?