我正在尝试编写一个Java程序来查询用户的密码。我面临的困难是,此Java程序是使用systemd
服务启动的。
我知道systemd
服务是要非交互式运行的。我正在尝试破解它。
我正在阅读有关Java中ProcessBuilder
来调用systemd-ask-password
命令的信息。
public static void main(String arg[]) {
try {
ProcessBuilder pb = new ProcessBuilder();// padd user nuxwdog:internalDB mkdtest1 @u"});
pb.command("/bin/bash", "-c", "systemd-ask-password internaldb: --no-output");
//pb.command("/bin/echo", "Hello", " world..."); <---- This WORKED as expected
pb.inheritIO();
Process p = pb.start();
int exitCode = p.waitFor();
assert exitCode == 0;
System.out.println(exitCode);
}
}
当我开始使用systemd时,得到以下journalctl
日志。我没有提示输入密码。
Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopping pki-tomcatd-nuxwdog@pki-tomcat.service...
Nov 27 18:25:35 localhost.localdomain java[7034]: 143
Nov 27 18:25:35 localhost.localdomain systemd[1]: pki-tomcatd-nuxwdog@pki-tomcat.service: Main process exited, code=exited, status=143/n/a
Nov 27 18:25:35 localhost.localdomain systemd[1]: pki-tomcatd-nuxwdog@pki-tomcat.service: Failed with result 'exit-code'.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopped pki-tomcatd-nuxwdog@pki-tomcat.service.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Started pki-tomcatd-nuxwdog@pki-tomcat.service.
是否可以从使用systemd服务启动的Java程序中以交互方式查询密码?