以下是我的代码。我不知道为什么它不起作用。调试后,我发现 runtimeProcess 返回“java.lang.ProcessImpl@1afe17b”并且 processComplete 返回 1。我想我无法构造我的命令我正在传递给 .exec。请帮帮我。
public static boolean backupDB(String Database, String Dbuser, String Password) throws IOException, InterruptedException
{
Process runtimeProcess;
try{
runtimeProcess = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/C","C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe -u"+Dbuser+" -p"+Password+Database+" >F:\\backup.sql"});
System.out.println(runtimeProcess);
int processComplete = runtimeProcess.waitFor();
System.out.println(processComplete);
if (processComplete == 0) {
System.out.println("Backup created successfully");
return true;
}
else{
System.out.println("Could not create the backup");
}
}catch (Exception ex)
{
ex.printStackTrace();
}
return false;