Skip to main content

How Can I execute cmd commands with RunTime??

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2012-11-19

Hello I've got a question How can execute cmd commands as admini.

I need to create Mysql backups using runtime but to do that I need to execute cmd as admin, I've got this code:

public static void main(String[] args) {
Runtime c = Runtime.getRuntime();
String cmd = "cmd /c cd C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin ";
String resp ="cmd /c mysqldump -u root -proot sakila > C:\\pr\\javaMike.sql";

try {
} catch (Exception e) {

with this I can make the backup file but save it without information, I mean 0kb and if I execute directly as admin in cmd, cand do it without problems, some solution for me?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2012-12-04

If you want to run several commands in the cmd shell then you can construct a single command like this: rt.exec("cmd /c start cmd.exe /K \"cd c:/ && dir\"");