• JAVA调用命令行2


    package loadMBQL;
    
    import java.io.File;
    import java.io.FilenameFilter;
    
    public class LoadMBQL {
    
    	/**
    	 * @param args
    	 * @throws Exception 
    	 */
    	public static void main(String[] args) throws Exception {
    		String exeName = "E:\ShenTong\bin\oimpexp.exe";
    		String srcFilePath = "E:/source data/MB_QL/node";
    		String ip = "localhost";
    		String dbname = "OSRDB";
    		String port = "2003";
    		String username = "SYSDBA";
    		String password = "szoscar55";
    		File srcFiles = new File(srcFilePath);
    		String cmdStr = "" -S SYSDBA -T "MB_QL" -Y UTF-8 -B 30 -A 1 -d 1 -H " + ip
    				+ " -D " + dbname + " -p " + port + " -U " + username + " -P "
    				+ password;
    		
    		FilenameFilter filter = new FilenameFilter() {
    			
    			@Override
    			public boolean accept(File dir, String name) {
    				if(name.toLowerCase().endsWith(".bin")){
    					return true;
    				}else{
    					return false;
    				}				
    			}
    		};
    		for (File f : srcFiles.listFiles(filter)) {
    			String cmd = exeName + " -F "" + f.getAbsolutePath() + cmdStr;
    			System.out.print(f.getAbsolutePath());
    			long start = System.currentTimeMillis();
    			cmdExec(cmd);
    			System.out.println("	using time: " + (System.currentTimeMillis() - start) / 1000 + "s!");
    		}
    	}
    	
    	public static void cmdExec(String cmdStr) throws Exception {
    		Process p = Runtime.getRuntime().exec(cmdStr);
    		StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(),
    				"ERROR");
    		errorGobbler.start();
    		StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(),
    				"STDOUT");
    		outGobbler.start();
    		int result = p.waitFor();
    		if (result != 0) {
    			throw new Exception("exe run failed!");
    		}
    	}
    
    }
    

      

  • 相关阅读:
    打印沙漏
    秋季学期学习总结
    bzoj1059[ZJOI2007]矩阵游戏 二分图匹配
    bzoj1055[HAOI2008]玩具取名 区间dp
    bzoj1053[HAOI2007]反素数ant
    bzoj1049[HAOI2006]数字序列
    bzoj1046[HAOI2007]上升序列
    bzoj1044[HAOI2008]木棍分割 单调队列优化dp
    bzoj3930[CQOI2015]选数 容斥原理
    bzoj1069 [SCOI2007]最大土地面积 旋转卡壳
  • 原文地址:https://www.cnblogs.com/yuwenfeng/p/3267265.html
Copyright © 2020-2023  润新知