原帖: http://stackoverflow.com/questions/12972619/runtime-getruntime-exec-in-java-with-file-redirection
代码类似于
try { Process p = Runtime.getRuntime().exec("/usr/local/mysql/bin/mysql -uroot dev_test <div/test_db.sql");
p.waitFor();
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) { System.out.println(line); }
input.close();
} catch (Exception e) { e.printStackTrace(); } }
不好使,怎么办?
windows下:
Process p = Runtime.getRuntime().exec(new String[] { "cmd", "/C", "mysql -u root dev_test < div\\test_db.sql" });
linux下:
String [] cmd = {"/bin/sh" , "-c", "/usr/local/mysql/bin/mysql -u root dev_test <div/test_db.sql"}; Process p = Runtime.getRuntime().exec(cmd);
也就是传数组进去~就OK了~~
|