【问题标题】:javac flag to print only the error locationsjavac 标志仅打印错误位置
【发布时间】:2011-05-15 10:21:14
【问题描述】:

是否可以让javac只输出错误位置和错误信息,隐藏源代码转储?

现在我明白了:

$ javac t.java
t.java:1: <identifier> expected
class {
     ^
t.java:2: reached end of file while parsing
bar
   ^
t.java:4: reached end of file while parsing

^
3 errors

我只想得到:

$ javac ... t.java
t.java:1: <identifier> expected
t.java:2: reached end of file while parsing
t.java:4: reached end of file while parsing

【问题讨论】:

    标签: javac verbosity


    【解决方案1】:

    我认为没有标志可以传递给 javac,但您可以通过任何删除多余行的程序简单地过滤输出。这里有一个 grep 的例子:

    javac t.java 2>&1 | egrep '^[a-zA-Z0-9_/]+\.java:[0-9]+: '
    

    如果您的文件名中有奇怪的字母,您可能必须更改与文件名匹配的部分 - 这似乎适用于 ASCII 子集。

    【讨论】:

    • 如果没有2&gt;&amp;1| 前面,您的管道解决方案将无法工作。我已经在编写脚本来正确解析 javac 的输出,我只是想避免这项工作。
    • 啊,对,感谢您注意到这一点。 (我并没有真正尝试使用真正的 javac,而是使用 cat javac-output | ...。)
    猜你喜欢
    • 2012-07-04
    • 1970-01-01
    • 2012-07-15
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 2012-12-14
    • 2014-04-15
    相关资源
    最近更新 更多