zoukankan      html  css  js  c++  java
  • 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!");
    		}
    	}
    
    }
    

      

  • 相关阅读:
    [Tool]使用ConfuserEx混淆代码
    Python_安装官方whl包和tar.gz包
    0017_集合的补充
    0016_练习题d2
    0015_各数据类型方法代码实现
    0014_基本数据类型及常用方法剖析
    0013_运算符
    0012_编码转换
    0011_练习题d1
    0010_while循环
  • 原文地址:https://www.cnblogs.com/yuwenfeng/p/3267265.html
Copyright © 2011-2022 走看看