ShellExecutor.java 1.21 KB
package com.sitech.util;

import java.util.ResourceBundle;

/**
 * 本类用于执行外部命令
 * 
 * @author winnerbao
 * 
 */
public class ShellExecutor {
	
	public static void executeCmd(String cmd) throws Exception {
		Runtime rt = Runtime.getRuntime();
		rt.exec(cmd);
		rt.gc();
	}

	private static String getFileName() {
		String result = "";
		ResourceBundle resourceBudle = ResourceBundle.getBundle("swap");
		result = resourceBudle.getString("filename");
		return result;
	}

	private static void WriteSwap(String cmd) throws Exception {
		Runtime rt = Runtime.getRuntime();
		rt.exec(cmd);
		rt.gc();
	}

	/**
	 * ??????????????
	 * 
	 * @param unit_id
	 * @param kpi_id
	 * @param kpi_value
	 */
	public static void WriteSwap(String unit_id, String kpi_id, String kpi_value) {
		String cmd = getFileName() + " " + unit_id + " " + kpi_id + " "
				+ kpi_value.replaceAll(" ", "");
		try {
			System.out.println(cmd);
			WriteSwap(cmd);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 标志仿
	 */
	public static String getWriteFlag() {
		// flag
		String result = "0";
		ResourceBundle resourceBudle = ResourceBundle.getBundle("swap");
		result = resourceBudle.getString("flag");
		return result;
	}
}