简体   繁体   中英

Masking password input from the console : Java with nohup command

I have an application where i have disabled the echoing for the password field after hitting the following command:

java -cp testJar.jar testClassFileInJar username

where username is a parameter provided to the main method of the class testClassFileInJar. After hitting enter, password is prompted. When i try the following command i could not make it run and the java1.out file is also empty.

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

Please suggest. To summarize, I need logging to be done in java1.out file and nohup command to be used with this java command.

I have used the following code in main method:

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 &

I tried with nohup but nothing worked. I then configured logger to the application( java.util.logging.Logger ) and used screen to run the following command.

java -cp testJar.jar testClassFileInJar username

In screen this command will prompt for the password.

Simply satisfied my requirement :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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