繁体   English   中英

屏蔽从控制台输入的密码:使用nohup命令的Java

[英]Masking password input from the console : Java with nohup command

我有一个应用程序,在单击以下命令后,我已禁用密码字段的回显:

java -cp testJar.jar testClassFileInJar username

其中username是提供给类testClassFileInJar的main方法的参数。 按下回车键后,提示输入密码。 当我尝试以下命令时,我无法使其运行,并且java1.out文件也为空。

nohup java -cp testJar.jar testClassFileInJar username & > java1.out

请提出建议。 总而言之,我需要在java1.out文件中记录日志,并在此Java命令中使用nohup命令。

我在主要方法中使用了以下代码:

Console console = System.console();
String userName = args[0];
String password = String.valueOf(console.readPassword("Password: "));
//other code logic for processing username and password

请尝试以下操作:

nohup java -cp testJar.jar testClassFileInJar username > java1.out &

我尝试了nohup,但没有任何效果。 然后,我将logger配置为应用程序( java.util.logging.Logger ),并使用screen运行以下命令。

java -cp testJar.jar testClassFileInJar username

在屏幕上,此命令将提示您输入密码。

完全满足我的要求:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM