如何将编译结果(使用 javac)存储到文本文件中? [英] How to store the result of compilation (using javac) to a text file?

查看:24
本文介绍了如何将编译结果(使用 javac)存储到文本文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编译一个 Hello World 程序.我使用 javac Hello_World.java.但是在 cmd 终端窗口中,它显示 semicolon is missing"编译错误.

I want to compile a Hello World program. I use javac Hello_World.java. However in cmd terminal window, it shows "semicolon is missing" compilation error.

如何将此编译错误存储到文本文件中?或者甚至一个字符串都可以.我如何捕捉"这个错误?我试过了

How do I store this compilation error into a text file? Or even a string will do. How do I "catch" this error? I tried

javac filename.java 2 > textfile.txt

但是 javac 仍然将 stderr 和 stdout 打印到屏幕上.

But javac still prints stderr and stdout to screen.

推荐答案

去掉2和>之间的空格

Get rid of the space between 2 and >

javac filename.java 2> textfile.txt

另一种方法是将 stderr 重定向到 stdout:

Another way is by redirecting stderr into stdout:

javac filename.java > textfile.txt 2>&1

更多信息:https://support.microsoft.com/en-us/help/110930/redirecting-error-messages-from-command-prompt-stderr-stdout

这篇关于如何将编译结果(使用 javac)存储到文本文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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