简体   繁体   English

Windows命令行上基于Eclipse的应用程序输出仅在通过管道传输时可见(在cmd中不直接显示)

[英]Output of application based on Eclipse on Windows command line only visible when piped (not directly in cmd)

We have a Java application based on Eclipse (main class implements IApplication ) that is started from the Windows command line. 我们有一个基于Eclipse的Java应用程序(主类实现IApplication ),该应用程序是从Windows命令行启动的。 Its output on System.out is not visible/printed into the command window from which it is started. 它在System.out上的输出不可见/不会打印到启动它的命令窗口中。 Nevertheless, when piping the output to more , the output is fine. 不过,将输出管道输送到more ,输出很好。 How come? 怎么会?

For example, consider helloworld.exe . 例如,考虑helloworld.exe When running C:\\>helloworld.exe in a command window, the application simply returns. 在命令窗口中运行C:\\>helloworld.exe时,应用程序仅返回。 But when running C:\\>helloworld.exe | more 但是,当运行C:\\>helloworld.exe | more C:\\>helloworld.exe | more , the screen shows C:\\>helloworld.exe | more ,屏幕显示

C:>helloworld.exe | C:> helloworld.exe | more 更多

hello world 你好,世界

C:> C:>

On linux, the output is fine. 在linux上,输出很好。 How to see the output on Windows, too? 如何在Windows上也看到输出?

Some reqested information: 一些要求的信息:

  • The application is quite large. 应用程序很大。 And I probably cannot cut it down. 而且我可能无法削减。 The output are simple calls to System.out.prinln("xxx"); 输出是对System.out.prinln("xxx");简单调用System.out.prinln("xxx");
  • Java version 1.8.0_60 , Eclipse 3.6.2 Java版本1.8.0_60 ,Eclipse 3.6.2
  • Using >std.txt 2>err.txt shows that output is indeed on stdout. 使用>std.txt 2>err.txt显示输出确实在stdout上。
  • Line endings are CR/LF 行尾为CR / LF

the .ini file is as follows .ini文件如下

--launcher.suppressErrors
-vmargs
-Xms256m
-Xmx4096m
-Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
-Djava.library.path=plugins

Maybe this issue is related? 也许这个问题有关?

如果您的应用程序是通过eclipse.exe (没有附加控制台)启动的,则将调用更改为使用eclipsec.exe (已附加有控制台,请在应用程序名称中记下c )。

You can launch Eclipse RCP based applications using equinox launcher as shown below: 您可以使用Equinox启动器启动基于Eclipse RCP的应用程序,如下所示:

java -jar plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar

Of course you have to find the correct version of equinox launcher you are using in your RCP Application. 当然,您必须找到在RCP应用程序中使用的正确的Equinox启动器版本。

This way you would see the console logs. 这样,您将看到控制台日志。

You can read more about it here: http://wiki.eclipse.org/index.php/Starting_Eclipse_Commandline_With_Equinox_Launcher 您可以在此处了解更多信息: http : //wiki.eclipse.org/index.php/Starting_Eclipse_Commandline_With_Equinox_Launcher

EDIT: The reason you don't get console logs when eclipse.exe based launcher is used is because eclipse.exe on Windows spawns a separate process which brings up another command prompt window. 编辑:使用基于eclipse.exe的启动器时未获得控制台日志的原因是,由于Windows上的eclipse.exe产生了一个单独的进程,该进程会弹出另一个命令提示符窗口。

You'd better use a framework to handle your logs like logback 您最好使用框架来处理日志,例如logback

This is much more portable and maintainable. 这更便于携带和维护。

In your example it seems that you have created an exe from your java code. 在您的示例中,您似乎已经从Java代码创建了一个exe。 My guess is that the packager you used to create the exe made some changes to the output target because it is a wrapper for your java program. 我的猜测是,您用来创建exe的打包程序对输出目标进行了一些更改,因为它是Java程序的包装。 Try creating a jar instead and try executing it by java -jar helloworld.jar. 尝试创建一个jar,然后尝试通过java -jar helloworld.jar执行它。

Is the string going to stderr in place of stdout? 字符串会去stderr代替stdout吗? (or the other way around depending on your expected behaviour). (或者反过来,取决于您的预期行为)。

https://support.microsoft.com/en-us/kb/110930 https://support.microsoft.com/zh-CN/kb/110930

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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