0

I would like execute the following command with Java:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\"mysqldump -u root --password=xxxx --routines database > C:\Users\john\Desktop\backup.sql

The command works perfectly when I use the Windows cmd.exe but not with my Java application.

cmd = "\"C:\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\\"mysqldump
-u root --password=xxxx --routines database > C:\\Users\\john\\Desktop\\backup.sql
Runtime runtime = Runtime.getRuntime(); 
process = runtime.exec(cmd);

I got the following error:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\"mysqldump -u root --password=xxxx --routines database > C:\Users\john\Desktop\backup.sql java.io.IOException: Cannot run program ""C:\Program": CreateProcess error=5, Access is denied

Do you have any idea?

Thank you.

3
  • Please show the Java code you're using to call this. Commented Dec 6, 2011 at 17:09
  • I gave it. This is the second block. Commented Dec 6, 2011 at 17:37
  • Ah, my mistake. I was distracted by odd syntax coloring. Commented Dec 6, 2011 at 17:45

2 Answers 2

3

You're trying to use a redirect (>) which is a function of the shell.

You don't have a shell, you're exec'ing the mysqldump process directly.

You either need to read the output stream from the process object and write it to a file yourself, or exec the windows shell to execute mysqldump for you along with the redirect.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I'm a bit confused with your answer. Can you give more details?
1

Error 5 is either 1) cannot access the file/folder or 2) don't have permissions.

Looks like the space in your 'Program File' directory name may be causing trouble causing trouble. Check where it says "Cannot run program ""C:\Program". This is obviously not a reference to the command you are trying to run. What I would do is add MySQL to your path and then just call the mysqldump command without the path to it. If you don't want to do this, you can define a system variable and reference it with %MYSQL_HOME%\mysqldump.

Once you have the path resolved, if this still doesn't work, you'll want to look at the permissions for the command. You'll need to make sure that the process has permission to execute the command. I think this in local admin groups or something like that.

Dollars to donuts its your path tho.

1 Comment

Thank you very much. I have created new environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.