Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Process p;
String command="mysqldump -u'scmuser' -p'scm$123' --routines db_name > /home/ubuntu/wh_demo_db_reset.sql";
p = Runtime.getRuntime().exec(command);
the dump file is not generated and not thrown any error. i am unable to predict the exact issue please help me. thanks in advance.
The metacharacter ">" is implemented by the shell; no shell is involved in running a program with Runtime.exec() so the last two arguments to mysqldump are garbage. Use the array argument form of Runtime.exec(); pass "/bin/sh" as the first argument, "-c" as the second, and your command line as the third; that way the shell metacharacters will be interpreted by /bin/sh.
You can form the cmd array as:
String[] cmdarray = {"/bin/sh","-c",command};
Process process = Runtime.getRuntime().exec(cmdArray);
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.