import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Time { public static void Test() { //1. executePath is the path where bat or cmd is located, for example: String excutePath = "E:\\weblogic\\user_projects\\domains\\cluster_domain\\cluster01.cmd"; Process process; try { // Execute CMD code and return a Process process = Runtime.getRuntime().exec(excutePath); InputStream is = process.getInputStream(); // Get the corresponding console output information InputStreamReader bi = new InputStreamReader(is); BufferedReader br = new BufferedReader(bi); String message; message = br.readLine(); while (message != null && !"".equals(message)) { // output the information System.out.println(message); message = br.readLine(); } } catch (IOException e) { e.printStackTrace (); return; } }
Start the weblogic child node
/** * Method to start the weblogic subnode service * */ public static void startserver() throws InterruptedException { // Runtime.getRuntime() returns the Runtime object of the current application Runtime nRuntime = Runtime.getRuntime(); // Process can control the execution of the child process or obtain information about the child process. Process nProcess = null; String nStartApp = "E:\\weblogic\\user_projects\\domains\\cluster_domain\\cluster01.cmd"; String nLine = null; try { nProcess = nRuntime.exec(nStartApp); // Read the return stream for correct execution BufferedReader nInfo = new BufferedReader(new InputStreamReader( nProcess.getInputStream())); nLine = nInfo.readLine(); while ((nLine = nInfo.readLine()) != null) { System.out.println(nLine); } // Read the return stream of the error execution BufferedReader nError = new BufferedReader(new InputStreamReader( nProcess.getErrorStream ())); nLine = nError.readLine(); while ((nLine = nError.readLine()) != null) { System.out.println(nLine); } } catch (IOException e1) { e1.printStackTrace(); } }