如何将javaw.exe控制台输出重定向到日志文件? [英] How do I redirect a javaw.exe console output to a log file?

查看:2623
本文介绍了如何将javaw.exe控制台输出重定向到日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从批处理文件启动我的Java程序。这是我想用来启动应用程序的脚本,但问题是我无法将控制台输出重定向到日志文件。任何人都可以提供任何提示而无需编辑任何代码,并使用Java命令行选项或什么?

I am wanting to start my Java program from a batch file. This is the script I want to use to start the app but the problem is that I am not able to get the console output to redirect to a log file. Can anyone offer any hints without having to edit any code, and by using Java command line options or something?

@echo off
set TASK=MyApp
TITLE %TASK%
start javaw.exe -cp .;Server.jar;Util.jar com.manage.Program %1 > log.log 2>&1
taskkill /T /FI "WINDOWTITLE eq %TASK%"

所以,上面的工作,实际上杀死了生成我的Swing应用程序的cmd窗口,但是它没有将任何内容记录到日志文件中,大概是因为start将进程从> log.log中分离出来2>& 1arg?

So, the above works, and actually kills the cmd window that spawns my Swing app, but it doesn't log anything to the log file, presumably because the "start" forked the process away from the "> log.log 2>&1" arg?

我可以通过使用start调用另一个批处理文件来修复它,但我希望得到一个更优雅的答案。

I could probably fix it by using start to call another batch file but I am hoping for a more elegant answer.

推荐答案

听起来你想要在没有实际显示控制台的情况下记录控制台输出。我可以看到三种类似的方法:

It sounds like you want to log console output without actually displaying a console. I can see three ways of doing something similar:


  1. 启动控制台最小化,这样就不那么烦人了。您可以通过创建批处理文件的快捷方式,然后设置快捷方式的属性来在最小化窗口中运行批处理文件,而不是使用默认设置普通窗口。

  1. Start console minimized, so that it's less annoying. You can do that by creating a shortcut to a batch file, and then setting the properties of the shortcut to run the batch file in a minimized window instead of using the default setting of "Normal window".

创建一个脚本以在隐藏窗口中运行bat文件,如下所示: http://gallery.technet.microsoft.com/ScriptCenter/en-us/8bbed56f-a7aa-491f-a296-687dd96098a3

Create a script to run the bat file in a hidden window, like so: http://gallery.technet.microsoft.com/ScriptCenter/en-us/8bbed56f-a7aa-491f-a296-687dd96098a3

使用第三方工具,例如 HSTART 。 (注意:根据djangofan,hstart不是为Java程序编写的,并没有真正起作用)

Use a third party tool, like hstart. (Note: according to djangofan, hstart was not written for Java programs and does not really work)

这篇关于如何将javaw.exe控制台输出重定向到日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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