Redirect operator in MySQL causes error in Java
I was instructed to convert a PHP script that executes a shell command(mysqldump command) to Java. There were various resource available and executing the mysqldump command was a peice of cake. However, I wasn't getting the output that I expect. The output continously says that the mysqldump command has failed and would show an error
table ">" not found
hmmm... let's try to look at my command(this is just a sample)
mysqldump -uUser -pPassword mydatabase mytable > mydumpfile.sql
it works ok with the command line... But not with Java. I searched google and found numerous answers.
The most obvious way perhaps is not to use the redirect operator(>) and just create a File within the Java program and write the InputStream you get from class Process's getInputStream() into the a FileWriter object. But a more likely solution was the one I found where you just change the ">" to -r. I'm not sure what the problem really was but it seems that there were localization issues and any non-english machine would probably get this wrong if used inside Java. I use a properties file so changing the command was easy(and flexible). The command now looks like this
mysqldump -uUser -pPassword mydatabase mytable -r mydumpfile.sql
hope this helps! :)
P.S. The redirect operator is not a MySQL only command. It lives natively on Windows or other operating systems as well.