I make backups of the MySQL database in a Java application. Here is the code:

try { Runtime rt = Runtime.getRuntime(); String executeCmd = "mysqldump.exe -u " + dbUser + " -p " + dbPass; executeCmd += " --all-databases > " + savePath; System.out.println(executeCmd); Process proc = rt.exec(executeCmd); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("<ERROR>"); while ( (line = br.readLine()) != null) System.out.println(line); System.out.println("</ERROR>"); int exitVal = proc.waitFor(); System.out.println("Process exitValue: " + exitVal); } catch (Throwable t) { t.printStackTrace(); } 

In response, I get exitValue: 1 . If you copy the output of System.out.pritln(executecmd); everything works fine in cmd. Can someone tell me what I'm doing wrong?

  • Try here to see how you can run the command differently with the output to the console of detailed results: ru.stackoverflow.com/q/828996/17609 - JuriySPb
  • The problem is that I have nothing to display in the console. No errors. The command executed through cmd does not give errors /. The same command through Java simply shows that it has failed. again without any errors. - Konstantin Prudnikov
  • Try adding --verbose to the command to output something to the console - YuriySPb 4:44 pm

1 answer 1

Problems here:

 String executeCmd = "mysqldump.exe -u " + dbUser + " -p " + dbPass; executeCmd += " --all-databases > " + savePath; 

Works in this form:

 String executeCmd = "mysqldump.exe -u " + dbUser + " -p" + dbPass+" dbName -r " + savePath; 

Something Java did not suit-all-databases and> instead of -r.