This content has been marked as final. Show 4 replies
You don't say what actually goes wrong when you execute this code, but you should always use exec(String) rather than exec(String).
I tried without CN option, command executed successsfully. keystore certificates are not created under current/any directory.
Process p = Runtime.getRuntime().exec("keytool -genkeypair -alias alias1 -keypass root -keystore keystore1 -storepass root -validity 60");
Tried exec(String) too. Same issue.
Well it must be created somewhere. Use ProcessBuilder instead of that, it gives you a chance to set the current directory. You should also eat the output produced so you can see whatever it may be trying to tell you.
EJP wrote:One can also set the working directory using one of the overloaded exec() methods but ProcessBuilder is my preferred approach since the API is more flexible.
Use ProcessBuilder instead of that, it gives you a chance to set the current directory.
Of course the OP should read and digest the whole of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html .