Java 1.5命令行口令屏蔽 [英] Java 1.5 Command Line Password Masking

查看:99
本文介绍了Java 1.5命令行口令屏蔽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,



我们的服务器运行的是Java 1.5,我无法尝试从命令行屏蔽用户输入。我正在执行一个jar文件(java -jar my.jar),并通过printlns通过命令行提示工作。我不能使用Java控制台。



感谢

解决方案

系统?在读取程序和程序之前,您可以尝试使用参数 -echo 运行系统程序 stty >

);
pb.start()。waitFor();
//这里读取密码
pb = new ProcessBuilder(stty,echo);
pb.start()。waitFor();

请注意,我没有尝试过这个!有些 stty 程序很高兴,有些不是(那些不需要他们的 stdin 来自 / dev / tty 以正常工作...)


All,

Our server is running Java 1.5 and I am having difficulty trying to mask user input from the command line. I am executing a jar file (java -jar my.jar) and am working through command line prompts via printlns. I cannot use Java Console.

Thanks

解决方案

On a Unix system? You could try running the system program stty with argument -echo before reading the program and the program stty echo afterwards.

ProcessBuilder pb = new ProcessBuilder("stty", "-echo");
pb.start().waitFor();
// Read the password here
pb = new ProcessBuilder("stty", "echo");
pb.start().waitFor();

Note that I have not tried this! Some stty programs are happy with it and some aren't (those that aren't need their stdin to come from /dev/tty to work right...)

这篇关于Java 1.5命令行口令屏蔽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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