Windows 上的 System.err 在哪里? [英] Where is System.err on Windows?

查看:56
本文介绍了Windows 上的 System.err 在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 Java GUI 的应用程序,可将一些诊断消息写入 System.out 和 System.err.在 Windows 上运行时,这些消息输出在哪里?(例如,在 Mac OS X 上,它们会打印到系统控制台日志中.)

I have a Java GUI-based application that writes some diagnostic messages to System.out and System.err. Where are these messages output when running on Windows? (For example, on Mac OS X, they're printed to the system console log.)

编辑

我应该补充一点,Java 应用程序被打包为 .exe,所以(现在)我无法使用 java 启动它.(我想我可以将单独的 .JAR 文件复制到 Windows 测试机器.)

I should add that the Java application is packaged as a .exe, so (right now) I can't launch it using java. (I can copy the individual .JAR files to the Windows test machine, I suppose.)

此外,这是我继承的一个应用程序,之前没有使用日志记录框架;我想修改它以使用一个,但我希望快速获得一些日志输出以立即诊断问题.

Also, it's an app I inherited that didn't use a logging framework before; I'd like to modify it to use one, but I was hoping to quickly get some log output to diagnose a problem right now.

推荐答案

这实际上取决于您启动应用程序的方式.例如,如果您要从 Windows 命令行提示符(例如 java -jar myApp.jar)启动您的 GUI,那么正如您所料,System.out 和 System.err 都会去控制台.如果您通过 Windows shell 本身启动(例如,双击可执行 JAR),那么据我所知,这些错误流将丢失.将应用程序设置为服务(但在您的情况下听起来不太可能)也会丢失输出流.

It really depends on how you launch your application. For example, if you were to launch your GUI from a windows command-line prompt (e.g. such as java -jar myApp.jar), then as you might expect both System.out and System.err would go to the console. If you're launching via the Windows shell itself (double-clicking on an executable JAR, for example) then these error streams are lost, to the best of my knowledge. Setting up execution of the app as a service (however unlikely it may sound in your situation) would also lose the output streams.

在输入和输出流中使用标准通常不是一个好主意,除非您希望您的程序在 shell 脚本类型的环境中被调用,这些环境是通用的通信渠道.正如您自己发现的那样,这些在 GUI 环境中通常没有很好的定义.如果您真的想在程序运行时捕获文本信息,请考虑使用真正的"日志记录框架(例如 log4j 或 java.util.logging 包)将消息捕获到日志中.

Use of the standard in put and output streams is not typically a good idea unless you're expecting your program to be called in a shell-script type environment where these are common channels for communication. As you've discovered yourself, these are typically not well defined in a GUI environment. If you really want to capture textual information while the program is running, consider using a "real" logging framework (such as log4j or the java.util.logging package) to capture messages to a log.

这篇关于Windows 上的 System.err 在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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