如何解除对 Java 启动进程的阻止? [英] How can I unblock from a Java started process?

查看:69
本文介绍了如何解除对 Java 启动进程的阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 cmd 行执行某些命令(假设为x")时,我收到以下消息:....按任意键继续 . . .".所以它等待用户输入解除阻塞.

When executing some command(let's say 'x') from cmd line, I get the following message: "....Press any key to continue . . .". So it waits for user input to unblock.

但是当我从 java 执行相同的命令 ('x') 时:

But when I execute the same command ('x') from java:

Process p = Runtime.getRuntime().exec(cmd, null, cmdDir);
// here it blocks and cannot use outputstream to write somnething
p.getOutputStream().write(..);

代码块...

我试图在进程的输出流中写入一些内容,但我怎么能做到这一点,因为代码永远不会到达那一行?

I tried to write something into the process's output stream, but how can i do that sice the code never reaches that line ?

推荐答案

我认为(虽然不能确定)您在谈论 Windows 而不是 Unix?

I think (although can't be certain) that you're talking about Windows rather than Unix?

如果是这样,则命令行进程实际上可能不是在等待 stdin 上的按键(或输入),而是在执行与旧的 DOS kbhit() 等效的操作 函数.

If so, it's possible that the command line process isn't actually waiting for a key press (or input) on stdin but instead doing the equivalent of the old DOS kbhit() function.

AFAIK 没有办法让这个函数相信键盘已经被按下而没有真正按下一个键.

AFAIK there's no way to make that function believe that the keyboard has been pressed without actually pressing a key.

为了测试这个理论,创建一个包含一些空行的文本文件input.txt",然后运行:

To test this theory, create a text file "input.txt" with some blank lines in it, and run:

foo.exe < input.txt

这将显示您的程序是否正在等待 stdin 或其他东西.

That will show whether your program is waiting on stdin or on something else.

这篇关于如何解除对 Java 启动进程的阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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