I have a bash script and inside this bash script I have a JAVARESULT variable like this :
JAVARESULT=`java -cp ... parser_file $file $someextravar`
and what I want is to catch in a log file the stderr and stdout of this result variable.
echo "$JAVARESULT" > $LOG_FILE
but i get only the stdout not the stderr. I tried with :
echo "$JAVARESULT" &> $LOG_FILE
but I don't get the java errors in the log file .
In every Unix based system every process have at least three file descriptors open. As you know, file descriptors are identified by numbers. This three standard file descriptors are:
- 0 for
- 1 for
- 2 for
What you want to do is redirect
stdout, and then redirect
stdout to a file. So, in your
JAVARESULT variable you'll just have to append:
What you're saying here is: redirect
stderr (file descriptor 2) to
stdout (file descriptor 1).