如何从控制台输入掩码密码?我正在使用Java 6.
我尝试过使用console.readPassword(),但它不起作用.一个完整的例子可能对我有帮助.
这是我的代码:
import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test
{
public static void main(String[] args)
{
Console console = System.console();
console.printf("Please enter your username: ");
String username = console.readLine();
console.printf(username + "\n");
console.printf("Please enter your password: ");
char[] passwordChars = console.readPassword();
String passwordString = new String(passwordChars);
console.printf(passwordString + "\n");
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个NullPointerException ...
有谁知道如何在控制台应用程序中使用RegisterHotKey/UnregisterHotKey API调用?我假设设置/删除热键是相同的,但是如何在按下键时收到回叫?
我看到的每个例子都是针对Winforms和使用的protected override void WndProc(ref Message m){...},我无法使用.
SetupHotkey一个不同的线程也没有任何反应.有什么想法吗?
class Program
{
static void Main(string[] args)
{
new Hud().Init(args);
}
}
class Hud
{
int keyHookId;
public void Init(string[] args)
{
SetupHotkey();
InitPowershell(args);
Cleanup();
}
private void Cleanup()
{
HotKeyManager.UnregisterHotKey(keyHookId);
}
private void SetupHotkey()
{
keyHookId = HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Control);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
}
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
//never executed
System.IO.File.WriteAllText("c:\\keyPressed.txt", "Hotkey pressed");
}
private static void InitPowershell(string[] args)
{
var config = …Run Code Online (Sandbox Code Playgroud) 我想在命令行Java程序中添加进度指示器.
例如,如果我使用的是wget,它会显示:
71% [===========================> ] 358,756,352 51.2M/s eta 3s
Run Code Online (Sandbox Code Playgroud)
是否可以在没有向底部添加新行的情况下更新进度指示器?
谢谢.
如何在Visual Studio中创建一个独立的exe.它只是一个简单的控制台应用程序,我认为用户不希望安装一个小的控制台应用程序.我使用visual studio命令提示符编译了一个简单的cpp文件.即使没有安装.NET框架,exe也会工作吗?我使用原生C++代码.
我正在用C#开发一个控制台应用程序,并且想知道是否有办法在我的应用程序中获得"复制粘贴"或"标记粘贴"功能,类似于或与标准Windows命令提示符相同或相同.这是一个疯狂的追逐或简单的应用变量吗?
它似乎是由IDE的内部向导生成的控制台应用程序项目无法由IDE管理的 版本资源<- note the emphasis here.
这个问题有解决方法吗?(我甚至准备写一个OTA向导)
如果我正在开发一个相当简单的基于Spring Boot控制台的应用程序,我不确定主执行代码的位置.我应该将它放在public static void main(String[] args)方法中,还是让主应用程序类实现CommandLineRunner接口并将代码放在run(String... args)方法中?
我将使用一个例子作为上下文.假设我有以下[基本]应用程序(编码为接口,Spring样式):
Application.java
public class Application {
@Autowired
private GreeterService greeterService;
public static void main(String[] args) {
// ******
// *** Where do I place the following line of code
// *** in a Spring Boot version of this application?
// ******
System.out.println(greeterService.greet(args));
}
}
Run Code Online (Sandbox Code Playgroud)
GreeterService.java(界面)
public interface GreeterService {
String greet(String[] tokens);
}
Run Code Online (Sandbox Code Playgroud)
GreeterServiceImpl.java(实现类)
@Service
public class GreeterServiceImpl implements GreeterService {
public String …Run Code Online (Sandbox Code Playgroud) 我使用控制台应用程序作为概念证明和获得异步返回值的新需求.
我发现我需要Task.WaitAll()在我的main方法中使用以避免需要异步"main()"方法,这是非法的.
我现在卡住试图弄清楚允许我使用泛型的重载,或者只返回我可以投射的对象,但是在Main()中.
.net c# console-application task-parallel-library async-await
我有一个C#控制台应用程序(A).我想从应用程序A(以同步方式)执行其他控制台应用程序(B),以便B使用相同的命令窗口.当B存在时,A应该能够读取B的退出代码.
怎么做?我只需要关于如何在同一个cmd窗口中运行这个其他应用程序的这个小技巧.
我有一个控制台程序,其中包含不同的组件,如下所示:
void start() {
while(true){
DoSomething();
Thread.Sleep(1000*5);
}
}
Run Code Online (Sandbox Code Playgroud)
我的主要入口点看起来像[伪代码]
Thread.Start(Componenet1.Start);
Thread.Start(Componenet2.Start);
while(true){
Console.Writeline("running");
Thread.Sleep(1000*5);
}
Run Code Online (Sandbox Code Playgroud)
在任何地方都没有Console.Reads.我的问题是SOMETIMES应用程序将运行良好,但然后停止,如果我按下窗口上的任何键它将再次开始工作.这种情况很少发生,但我在100+ VM上部署了这个程序,在自动化环境中全天候运行.
另外在电脑上我有一些AHK脚本和其他操纵鼠标的东西,但不确定它是否与它有任何关系.
另请注意,有时CPU可以在机器上以100%的速度运行,因此可能是线程优先级问题?
SOLUTION:您需要禁用快速编辑模式.这是使用C#代码执行此操作:
// http://msdn.microsoft.com/en-us/library/ms686033(VS.85).aspx
[DllImport("kernel32.dll")]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
private const uint ENABLE_EXTENDED_FLAGS = 0x0080;
static void Main(string[] args)
{
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
SetConsoleMode(handle, ENABLE_EXTENDED_FLAGS);
Run Code Online (Sandbox Code Playgroud) c# ×6
console ×3
java ×3
.net ×1
async-await ×1
automation ×1
c++ ×1
command-line ×1
copy-paste ×1
delphi ×1
executable ×1
ide ×1
masking ×1
passwords ×1
pinvoke ×1
spring-boot ×1
versioning ×1
winapi ×1