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("\tusing 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!");

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值