Bash – How to redirect only stderr

bashcompilingio-redirection

I am having a bit of trouble doing this. I am required to run a compiled .java file and redirect only stderr to a file called error. So the .java file is named javaProgram.java.

This is what I have tried:

java javaProgram 2> error

However when I

cat error

it appears that there is stuff in there, even when I know for a fact that the specific .java file has no errors. Am I doing something wrong? All I want this error file to display is errors, not anything else.

Best Answer

Your first try was correct; 2>filename is how you redirect stderr. It may be the case that your program is writing some non-errors to stderr, or the java program is running other programs that output to stderr.

Related Question