English 中文(简体)
将Java管道到Grep:为什么不起作用?
原标题:Pipe Java to Grep: Why not working?

我正在尝试在Bash中运行这个可怕地简单的命令。

java -cp nasa-top-secret.jar gov.nasa.RocketToMoon | grep -v codehaus

但是 grep 不起作用(它无法过滤出我的字符串)。我该如何使用 grep 过滤我的 java 输出?

最佳回答

输出可能在 STDERR 上,请尝试这个:

java -cp nasa-top-secret.jar gov.nasa.RocketToMoon 2>&1 | grep -v codehaus
问题回答

可能的情况。

  1. you actually have all the lines with "codehaus", so grep -v gives you nothing. I assume you know what -v stands for.
  2. your java program did not print anything to stdout. check your source and make sure your program spits out to stdout. Otherwise, check if its stderr that your program is spitting out.

可能的故障排除步骤:

  1. remove the pipe to grep, run only the java program and make sure your program has output.
  2. put 2>&1 at the end of the command and try again with grep




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签