I suspect because you've separated the cmdArray
into only two elements that mysqldump
is treating the second array element as a single command line argument.
Also, you've not paying attention to the output of the process which makes it really difficult for your to ascertain what the processing is trying to tell.
You "base" command also includes mysqldump
...
"mysqldump -u " + getSourceUsername() + " -p" + getSourceServerPassword()
+ " --add-drop-database -B " + getSourceDatabase() + " -r " + path;
as part of the command, which means you are effectively calling mysqldump mysqldump
...
Instead of using a String
, place all your commands into some kind of list instead.
Remember, if it's separated by a space on the command line, it's a separate command/element
List<String> args = new ArrayList<String>
args.add("C:\\wamp\\bin\\mysql\\mysql5.5.24\\bin\\mysqldump.exe");
//...
args.add("-u");
args.add(getSourceUsername());
args.add("-p" + getSourceServerPassword()); //?? Is this a single command?
args.add("--add-drop-database");
args.add("-B");
args.add(getSourceDatabase());
args.add("-r");
args.add("path);
//...
Then use ProcessBuilder
ProcessBuilder pb = new ProcessBuilder(args);
pb.redirectError();
Process p = pb.start();
InputStream is = p.getInputStream();
int in = -1;
while ((in = is.read()) != -1) {
System.out.print((char)in);
}
int processCompleted = p.waitFor();
Remember, you should never ignore the output from a process, even if you don't care, you should attempt to consume the content from the InputStream
as some processes will hang if there output stream is not read.