Operating System - Linux
1828484 Members
2785 Online
109978 Solutions
New Discussion

java command and grep on output

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

java command and grep on output

Hello

I'd like to save the result of a java ksh command. This command normally show something likke that:

java.sql.SQLException: ORA-01017: invalid username/password; logon denied

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processErr

....


Example: java -jar test.jar | tee -a /tmp/test.tmp

The full result comes on screen but no lines in the /tmp file.

why ?
I think that it's somewhere a problem with standard output but how to do the trick !

Thanks in advance
Bests Regards
Den
2 REPLIES 2
Matti_Kurkela
Honored Contributor
Solution

Re: java command and grep on output

Perhaps the missing messages are not sent to standard output stream (stdout, file descriptor #1), but to standard error stream (stderr, file descriptor #2).

If you wish to capture both, try a command like:

java -jar test.jar 2>&1 | tee -a /tmp/test.tmp

The "2>&1" merges the standard error stream to the output stream, so that the content of both streams can be received by the pipe.

(Nitpick: "java" is not a ksh command, as it is not specific to ksh in any way, nor built in to it. It's a wholly independent program binary, more specifically a Java bytecode interpreter/JIT compiler. It is most commonly known as JVM = Java Virtual Machine.)

MK
MK
Leo The Cat
Regular Advisor

Re: java command and grep on output

Thanks Matti, efficient answer !