Note that there are some explanatory texts on larger screens.

plurals
  1. POKeytool usage with Runtime.getRuntime().exec() under Linux
    text
    copied!<p>I'd like to call the java keytool during runtime execution providing dynamic arguments. Here's what is working under Windows, but not under Linux (Ubuntu) same Java 1.6.0:</p> <pre><code>File f = new File("mykey.jks"); StringBuilder command = new StringBuilder(); command.append(System.getProperty("java.home") + System.getProperty("file.separator") + "bin" + System.getProperty("file.separator") + "keytool"); command.append(" -genkey"); command.append(" -dname \"cn=foo,ou=bar,o=company,c=CH\""); command.append(" -alias myProduct"); command.append(" -keypass " + "testtest"); command.append(" -keystore " + f.getAbsolutePath()); command.append(" -storepass " + "testtest"); command.append(" -validity " + 3650); final Process pr = Runtime.getRuntime().exec(command.toString()); BufferedReader input = new BufferedReader(new InputStreamReader( pr.getInputStream())); String line = null; while ((line = input.readLine()) != null) { System.out.println(line); } int exitVal = -1; try { exitVal = pr.waitFor(); System.out.println("Exited with error code " + exitVal); } catch (InterruptedException e) { // handle } </code></pre> <p>The Output under Linux is </p> <blockquote> <p>keytool error: java.io.IOException: Invalid keyword ""CN"</p> </blockquote> <p>Running the command in the Linux command line (not starting in java), the code works. What am I doing wrong and how would the <code>String[]</code> look like when using</p> <pre><code>Runtime.getRuntime().exec(String[]) </code></pre> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload