.getRuntime().exec() - with long command

P

petr cezar

hello,

i'm trying to run 'keytool' program from within my application by this way:

String cmdline = "keytool -genkey" +
" -dname \"cn=" + "MyName" + ", ou=" + "Development" + ", o=" + "IBM" + ", c="+ "CZ" + "\"" +
" -keyalg " + "DSA" +
" -keysize " + 1024 +
" -alias " + "MujFirstKey" +
" -keypass " + "somepasswd" +
" -keystore " + "/home/petr/MyKeystore" +
" -storepass " + "somepasswd" +
" -validity " + 180;

try {
Process p = Runtime.getRuntime().exec(cmdline);
.......

but 'keytool' always prints out only some help messages and that's all.
it seems like some of the command parameters are not in correct form, mabye
spaces or those in quotes, but i don't know...

does anybody know what's wrong with that code?

thank you very much,
and, please, excuse my pure english
-petr
 
G

Gordon Beaton

i'm trying to run 'keytool' program from within my application by this way:

String cmdline = "keytool -genkey" +
" -dname \"cn=" + "MyName" + ", ou=" + "Development" + ", o=" + "IBM" + ", c="+ "CZ" + "\"" +
" -keyalg " + "DSA" +
" -keysize " + 1024 +
" -alias " + "MujFirstKey" +
" -keypass " + "somepasswd" +
" -keystore " + "/home/petr/MyKeystore" +
" -storepass " + "somepasswd" +
" -validity " + 180;

try {
Process p = Runtime.getRuntime().exec(cmdline);
.......

but 'keytool' always prints out only some help messages and that's
all. it seems like some of the command parameters are not in correct
form, mabye spaces or those in quotes, but i don't know...

does anybody know what's wrong with that code?

Try it like this instead:

String[] cmdline = {
"keytool",
"-genkey",
"-dname",
(etc...)
}

i.e. exactly one argument per array element, without any extra quotes
(spaces shouldn't matter).

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top