Runtime.getRuntime()。exec提示时传递参数 [英] Runtime.getRuntime().exec to pass parameter when prompted

查看:2071
本文介绍了Runtime.getRuntime()。exec提示时传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的java语句从java代码启动PostgreSQL服务器。我使用Runtime.getRuntime()。exec()方法来实现这一点。

I am using the below java statement to start the PostgreSQL server from java code. I am using Runtime.getRuntime().exec() method to achieve this.

 final Process startServer = Runtime.getRuntime().exec("PostgreQL -D data/dir/ start");

这里,当服务器启用SSL并且密钥受密码保护时,在命令行中会提示密码(见下面的行)。在这种情况下,我如何传递密码。

Here when the server is SSL enabled and if the key is password protected, in command line it prompts for password (see below lines). In this case how can I pass the password.

Is server running?
starting server anyway
waiting for server to start......Enter PEM pass phrase:....

当提示时,我们是否有任何选项将密码作为参数传递?或在PostgreSQL中启动时,我们有任何规定来传递密钥(像PostgreSQL -d data / dir / -keyPass password start)?

Do we have any option to pass the password as a parameter, when prompted ? or in PostgreSQL while starting do we have any provision to pass the keypassword (like - " PostgreSQL -d data/dir/ -keyPass password start") ?

出来。任何帮助或建议将真正感谢。提前感谢。

Please help me out. Any help or suggestion will be really appreciated. Thanks in advance.

推荐答案

您可以打开该进程的OutputStream,并传递将由服务器读取的密码短语你输入的是来自STDIN。

You can open the OutputStream of the process and pass the passphrase which will be read by the server as if you typed it is coming from STDIN.

final Process startServer = Runtime.getRuntime().exec("PostgreQL -D data/dir/ start");
PrintStream ps = new PrintStream(startServer.getOutputStream());
ps.println(passPhrase);

这篇关于Runtime.getRuntime()。exec提示时传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆