Java 执行运行时命令 Runtime

 
package cn.com.cloud.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 执行运行时命令
 * @author 李海云
 * @email [email protected]
 * @date 2012-01-12 15:21
 */
public class CommandUtil {
	/**
	 * executeCommand
	 * @param command
	 * @throws IOException 
	 */
	public static void executeCommand(String command) throws IOException {
		Runtime runtime = Runtime.getRuntime();
		Process process;
		process = runtime.exec(command);
		BufferedReader br = new BufferedReader(new InputStreamReader(process
				.getInputStream()));
		String inline;
		while ((inline = br.readLine()) != null) {
			System.out.println(inline);
		}
		br.close();
	}
//	public static void main(String[] args) {
//		String cmd_OracleDBConsoleorcl = "cmd /c start net start OracleDBConsoleorcl";
//		String cmd_OracleJobSchedulerORCL = "cmd /c start net start OracleJobSchedulerORCL";
//		String cmd_OracleOraDb10g_home1iSQLxPlus = "cmd /c start net start OracleOraDb10g_home1iSQL*Plus";
//		String cmd_OracleOraDb10g_home1TNSListener = "cmd /c start net start OracleOraDb10g_home1TNSListener";
//		String cmd_OracleServiceORCL = "cmd /c start net start OracleServiceORCL";
//		String cmd_services_msc = "cmd /c start services.msc";
//		try {
//			CommandUtil.executeCommand(cmd_OracleDBConsoleorcl);
//			CommandUtil.executeCommand(cmd_OracleJobSchedulerORCL);
//			CommandUtil.executeCommand(cmd_OracleOraDb10g_home1iSQLxPlus);
//			CommandUtil.executeCommand(cmd_OracleOraDb10g_home1TNSListener);
//			CommandUtil.executeCommand(cmd_OracleServiceORCL);
//			CommandUtil.executeCommand(cmd_services_msc);
//			CommandUtil.executeCommand("cmd /c ipconfig");
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
}

你可能感兴趣的:(Java)