-1

以下は私のコードです.なぜそれが機能していないのかわかりません.デバッグした後、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;
4

2 に答える 2

0

簡単な方法は、最初にコマンド ラインでコマンドを試し、String[] 配列ではなく String をパラメーターとして使用することです。

String cmd = "C:\\Program     Files\\MySQL\\MySQL Server 5.5\\bin\\mysqldump.exe -u"+Dbuser+" -p"+Password+Database+"       >F:\\backup.sql"
Runtime.getRuntime().exec(cmd);

それができない場合は、いつでも次の方法を使用して、舞台裏で何が起こっているかを把握できます。

Runtime r = Runtime.getRuntime();
r.traceInstructions(true);
r.traceMethodCalls(true);
r.exec("your command")
于 2013-07-06T08:35:56.963 に答える