package com.wz;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
public class CMDTest {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
BufferedReader buf = null;
Runtime run = Runtime.getRuntime();
//MySql
String cmd = "mysqldump -uroot -p123456 --default-character-set=utf8 --no-autocommit --skip-opt --skip-tz-utc"
+ " -R --verbose --hex-blob --databases test > C:/app.sql";
//Oracle
//cmd = "exp wang/123456 owner=(wang) file=C:/local.dmp";
try{
//Win
Process process = run.exec(new String[]{"cmd", "/c", cmd});
//Linux
//process = run.exec(new String[]{"/bin/sh", "-c", cmd});
buf = new BufferedReader(new InputStreamReader(process.getErrorStream(),
Charset.forName("GBK")));
String line = null;
while ((line = buf.readLine()) != null) {
sb.append(line + "\r\n");
}
}catch(Exception e){
e.printStackTrace();
}
System.out.println(sb.toString());
}
}
Run command
最新推荐文章于 2024-03-22 09:47:13 发布