【问题标题】:Masking password input from the console : Java with nohup command从控制台屏蔽密码输入:使用 nohup 命令的 Java
【发布时间】:2012-09-27 07:32:00
【问题描述】:

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

java -cp testJar.jar testClassFileInJar username

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

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

请提出建议。总而言之,我需要在 java1.out 文件和 nohup 命令中完成日志记录,以便与此 java 命令一起使用。

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

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

【问题讨论】:

    标签: java linux logging jar console


    【解决方案1】:

    请尝试以下方法:

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

    【讨论】:

      【解决方案2】:

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

      java -cp testJar.jar testClassFileInJar username
      

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

      刚好满足我的要求:)

      【讨论】:

        猜你喜欢
        • 2011-12-29
        • 2011-04-09
        • 1970-01-01
        • 2011-03-25
        • 2016-02-15
        • 2021-09-27
        • 2013-12-18
        • 1970-01-01
        相关资源
        最近更新 更多