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

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

问题描述

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

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和>

javac filename.java 2> textfile.txt

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

Another way is by redirecting stderr into stdout:

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

更多信息: 查看全文

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