在 Spring 引导应用程序中以编程方式执行命令

Execute a command programmatically in Spring Boot app

我想在SpringBoot应用中执行这条命令:

keytool -import -keystore trustStore.jks -file certCA.der -storepass example << EOF
\ yes
\ EOF

我的问题是我无法在我的代码中自动插入“是”。

Runtime.getRuntime().exec("keytool -import -keystore trustStore.jks -file certCA.der -storepass example");

我该怎么做?

在命令中使用 -noprompt 参数