From dd4a68a7cae09bd79df7aa3a18afce5639360cb1 Mon Sep 17 00:00:00 2001
From: 军 <军@hp-pc>
Date: 星期一, 08 十月 2018 17:39:00 +0800
Subject: [PATCH] 在BattTestData.java文件中添加启动自动建表的jar文件的方法

---
 gx_tieta/src/com/fgkj/dao/BattTestData.java |   75 +++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/gx_tieta/src/com/fgkj/dao/BattTestData.java b/gx_tieta/src/com/fgkj/dao/BattTestData.java
index 1bae5f1..1c03d83 100644
--- a/gx_tieta/src/com/fgkj/dao/BattTestData.java
+++ b/gx_tieta/src/com/fgkj/dao/BattTestData.java
@@ -1,5 +1,9 @@
 package com.fgkj.dao;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
 public class BattTestData {
 	final public static int BATT_DISCHARGE=3;//鏀剧數娴嬭瘯
 	final public static int BATT_RES=5;//鍐呴樆娴嬭瘯
@@ -71,6 +75,77 @@
 	
 	//钀藉悗鍗曚綋鍙傛暟锛堢粍绔數鍘�>鏍囩О*test_stop锛�
 	public static final float test_stop = 0.9f;
+	
+	//鍚姩鍒涘缓鏁版嵁搴撶殑jar鏂囦欢
+	public static void run_cmdOld() {
+		String path=System.getProperty("user.dir");
+		String realapth=path.substring(0,path.lastIndexOf("\\"));
+		//System.out.println(realapth);
+		String strcmd="cmd /c start  "+realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
+		//
+        Runtime rt = Runtime.getRuntime(); //Runtime.getRuntime()杩斿洖褰撳墠搴旂敤绋嬪簭鐨凴untime瀵硅薄
+        Process ps = null;  //Process鍙互鎺у埗璇ュ瓙杩涚▼鐨勬墽琛屾垨鑾峰彇璇ュ瓙杩涚▼鐨勪俊鎭��
+        try {
+            ps = rt.exec(strcmd);   //璇ュ璞$殑exec()鏂规硶鎸囩ずJava铏氭嫙鏈哄垱寤轰竴涓瓙杩涚▼鎵ц鎸囧畾鐨勫彲鎵ц绋嬪簭锛屽苟杩斿洖涓庤瀛愯繘绋嬪搴旂殑Process瀵硅薄瀹炰緥銆�
+            ps.waitFor();  //绛夊緟瀛愯繘绋嬪畬鎴愬啀寰�涓嬫墽琛屻��
+        } catch (IOException e1) {
+            e1.printStackTrace();
+        } catch (InterruptedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        int i = ps.exitValue();  //鎺ユ敹鎵ц瀹屾瘯鐨勮繑鍥炲��
+        if (i == 0) {
+            System.out.println("鎵ц瀹屾垚.");
+        } else {
+            System.out.println("鎵ц澶辫触.");
+        }
+
+        ps.destroy();  //閿�姣佸瓙杩涚▼
+        ps = null;   
+    }
+	
+	//鍚姩鍒涘缓鏁版嵁搴撶殑jar鏂囦欢
+	public static void run_cmd() {
+		String path=System.getProperty("user.dir");				//myeclipse涓幏鍙栫殑鐩綍(鑾峰彇鍒扮殑鏄痶omcat/bin)鍜屽垎绂婚」鐩幏鍙栧埌鐨勮矾寰�(tomcat)涓嶄竴鏍�
+		//System.out.println(path);
+		String realapth=path.substring(0,path.lastIndexOf("\\"));
+		String strcmd="cmd /c start  "+realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
+		String batPath = realapth+"/webapps/cmd_BTSE_DB_Builder.cmd";
+		File f = new File(path);
+        //System.out.println("File :"+f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd");
+        //batPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd";
+		String jarPath = "";
+		if(path.endsWith("bin")){
+			f = f.getParentFile();
+        }
+		
+		jarPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"BTSE_DB_Builder.jar";				//涓荤▼搴忎腑jar鐨勭洰褰�
+        //strcmd = "cmd /c start "+batPath;
+        strcmd = ("cmd /c start ")+jarPath.replaceAll(" ", "\" \"");			//淇缁濆璺緞涓瓨鍦ㄧ┖鏍兼椂鎵ц涓嶆垚鍔焍ug
+        Process child = null;
+		InputStream in = null;
+		try {
+			//System.out.println(strcmd);
+			child = Runtime.getRuntime().exec(strcmd);
+			in = child.getInputStream();
+			int c;
+			while ((c = in.read()) != -1) {
+				//System.out.print((char)c);
+			}
+			in.close();
+			try {
+				child.waitFor();
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			//System.out.println("Run Bat OK....");
+		} catch (IOException e) {
+			e.printStackTrace();
+		} 
+    }
+	
 	//鍒ゆ柇鐢垫睜缁勭殑褰撳墠鐘舵��
 	public static String battState(int num){
 		String state="";

--
Gitblit v1.9.1