I'm trying to grep on output from the commands:
java -version
java -XshowSettings
but it seems like they refuse to be redirected or piped.
I tried
java -version | grep whatever
java -version > jout.txt
but both just print the output to the screen.
What is going on?
Thanks, Gilad.
You need to redirect to stdout before you can pipe like that. Those messages go to stderr by default, rather than stdout; that means that grep
won't see the messages, and they'll just get printed to the console.
If this is Linux, try
java -version 2>&1 | grep whatever
and it should work. This will take all output to stderr from the java
execution, and redirect it so that it goes to the same place as stdout; your grep
invocation will then be able to see it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With