0
我想在运行时执行过程中调用java keytool来提供动态参数。 这里是工作在Windows下,但不是在Linux(Ubuntu的)相同的Java 1.6.0:Runto.getRuntime()的Keytool用法。Linux下的exec()
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
}
Linux下的输出
keytool error: java.io.IOException: Invalid keyword ""CN"
在Linux命令行运行命令(不从java开始),代码工作。我在做什么错了,会怎么看String[]
提前使用
Runtime.getRuntime().exec(String[])
感谢时一样!
我试过使用String [] - 符号,但没有得到它的工作。我该如何安排参数(特别是-dname“....”参数)? –
编辑我的问题以显示用法 – jontro
感谢@Bengt,它工作的很好!我总是尝试使用String args [] = {arg1,arg2,“-dname dNameArguments”}; –