import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class test {
public static void main(String[] args) throws IOException, InterruptedException{
String str = "mysqldump --default-character-set=utf8 --host=xx --port=3306 --user=root --password=1111 db_name tableA > /home/11.sql";
String[] cmd = new String[]{"/bin/sh","-c",str};
Process process = Runtime.getRuntime().exec(cmd);
printMessage(process.getInputStream());
printMessage(process.getErrorStream());
if (process.waitFor() == 0) {
System.out.println("ok");
}
else{
System.out.println("errror");
}
}
private static void printMessage(final InputStream input) {
new Thread(new Runnable(){
@Override
public void run() {
Reader reader = new InputStreamReader(input);
BufferedReader bf = new BufferedReader(reader);
String line = null;
try{
while((line=bf.readLine())!=null){
System.out.println(line);
}
}
catch(IOException e){
e.printStackTrace();
}
}}).start();
}
}