2018-10-08 dd4a68a7cae09bd79df7aa3a18afce5639360cb1
在BattTestData.java文件中添加启动自动建表的jar文件的方法
1个文件已修改
75 ■■■■■ 已修改文件
gx_tieta/src/com/fgkj/dao/BattTestData.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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()返回当前应用程序的Runtime对象
        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中获取的目录(获取到的是tomcat/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(" ", "\" \"");            //修复绝对路径中存在空格时执行不成功bug
        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="";