java Java执行弹出一个新窗口并立即消失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16824190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:05:30  来源:igfitidea点击:

Java execution pops a new window and immediately disappears

java

提问by Dan477

This morning when I executed a simple hello world Java application from the command line on a Windows 7 machine, the response appeared below the command. Something like this:

今天早上,当我从 Windows 7 机器上的命令行执行一个简单的 hello world Java 应用程序时,响应出现在命令下方。像这样的东西:

java HelloWorld Hello world

java HelloWorld 你好世界

Now the same command pops up a new window and immediately disappears. I put in a System.console().readLine("enter to continue"); and that appears as expected. Upon pressing enter the new window closes down.

现在同样的命令会弹出一个新窗口并立即消失。我输入了 System.console().readLine("enter to continue"); 这看起来像预期的那样。按回车键后,新窗口关闭。

How do I prevent this from happening? (1.7_21)

我如何防止这种情况发生?(1.7_21)

Additional clarity:

额外的清晰度:

The code:

代码:

public class HelloWorld {
    public static void main() {
        System.out.println("Hello World");
    }
}

Steps taken:

采取的步骤:

  1. open a DOS window by Start/Run... cmd
  2. in the DOS window I cd to the proper folder
  3. in the DOS window I enter: java HelloWorld
  4. A new "java" window opens for about 1/10 of a second (The icon on the task bar is the Java icon.
  5. I issue the command: java -verbose HelloWorld
    The same window opens and I can see all the classes loading but then immediately closes
    If I select (very quickly) some of the text about loading classes, I can see, through task manager, that Java is running.
  6. issue the command: java
    I would expect to get "usage" back. The same window appears then disappears right-a-way.
  1. 通过开始/运行... cmd 打开 DOS 窗口
  2. 在 DOS 窗口中,我 cd 到正确的文件夹
  3. 在 DOS 窗口中我输入:java HelloWorld
  4. 一个新的“java”窗口打开大约 1/10 秒(任务栏上的图标是 Java 图标。
  5. 我发出命令: java -verbose HelloWorld
    打开同一个窗口,我可以看到所有正在加载的类,但随后立即关闭
    如果我(非常快速地)选择了一些关于加载类的文本,我可以通过任务管理器看到那个 Java在跑。
  6. 发出命令:java
    我希望能恢复“使用”。相同的窗口出现然后立即消失。

My question is, "Why is the java executable opening this java window?" On other machines it puts it's output right in the same DOS window.

我的问题是,“为什么 java 可执行文件打开这个 java 窗口?” 在其他机器上,它把它的输出放在同一个 DOS 窗口中。

As another note Netbeans doesn't display the output in the output window either, in this case it appears to be totally lost. I can step through programs, but the output is not displayed in the output window.

另请注意,Netbeans 也不会在输出窗口中显示输出,在这种情况下,它似乎完全丢失了。我可以单步执行程序,但输出未显示在输出窗口中。

P.S. I'm not a new-be, I've been running Java from the command line for years and this just started to happen. (and no I don't know what changed, I believe the machine received some sort of security patch from our corporate security staff. I'm unable to get from them what changed.)

PS 我不是新手,多年来我一直从命令行运行 Java,而这才刚刚开始发生。(不,我不知道发生了什么变化,我相信这台机器从我们的公司安全人员那里收到了某种安全补丁。我无法从他们那里得知发生了什么变化。)

回答by DigCamara

When you run a command line executable in Windows and it finishes, that's pretty much what should happen. Easiest way to diagnose what really's happening is to open an actual command prompt window (Start->cmd) and run the command in that window .

当您在 Windows 中运行命令行可执行文件并完成时,这几乎就是应该发生的事情。诊断实际情况的最简单方法是打开实际的命令提示符窗口 ( Start->cmd) 并在该窗口中运行命令。

回答by Francisco Javier Banos Lemoine

I started to experience the same problem after installing JDK 8.0.77. I am positive the new version has nothing to do with the problem. I just solved it by removing 'C:\ProgramData\Oracle\Java\javapath;' from the PATH environment variable. Hope this works for you too (although my answer might be too late). BTW, I have not experienced issues with other tools (Maven, Tomcat, Eclipse, etc.) I have and that depend on Java configuration.

安装 JDK 8.0.77 后我开始遇到同样的问题。我很肯定新版本与问题无关。我刚刚通过删除 'C:\ProgramData\Oracle\Java\javapath;' 解决了它 来自 PATH 环境变量。希望这也适用于您(尽管我的回答可能为时已晚)。顺便说一句,我没有遇到过其他工具(Maven、Tomcat、Eclipse 等)的问题,这取决于 Java 配置。

回答by user11960229

try running by administrator, it works for me.

尝试由管理员运行,它对我有用。