Executing external process with Runtime.getRuntime().exec()

Share

slamo 3alekom,
I want to execute the following external process in the command prompt of windows xp.
in command prompt:

mysqldump --user=root --password=root myDB > C:/Backup/B.sql

and what I tried in java:

String mysql =
"mysqldump --user=root --password=root myDB > C:/Backup/B.sql";

Runtime.getRuntime().exec(mysqld);

I tries also to add the line as array of strings (exec() has an overloaded version which support it), and also to execute mysqldump with the full path
(C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump.exe)
...but nothing works...any help will be very appreciated

thanx

{{{
public static void main(String...args) throws IOException{
Runtime rt = Runtime.getRuntime();
String[] cmdarray = {
"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqldump",
"--user=root",
"--password=root",
"myDB"
};

Process process = rt.exec(cmdarray);
PrintWriter writer = new PrintWriter(new FileOutputStream("output.sql"));
String s;
BufferedReader input =
new BufferedReader(
new InputStreamReader(process.getInputStream()));
while((s = input.readLine()) != null){
writer.println(s);
}
writer.flush();
writer.close();
input.close();

/*writer = new PrintWriter(new FileOutputStream("error.sql"));
BufferedReader error =
new BufferedReader(
new InputStreamReader(process.getErrorStream()));
while((s = error.readLine()) != null){
writer.println(s);
}
writer.flush();
writer.close();
error.close();*/
}
}
}}}