Redirect Output and Error in 2 different files

hi,
i want to redirect my output & error if generated to two different files. I
have written the code for redirecting the output, i dnt have ne idea how to
go abt it for errors. I tried spooling which was given in one of the
threads on this forum.But it didn't work.The script i wrote as a lot of
select queries only and it works fine.

-----SCRIPT------

{
echo "SELECT empno from emp where rownum<5;"
} | sqlplus -s $username/$password@DB >> $root_dir/$filename

This is the basic command to redirect the output and error to two different files

prog >>& file	prog >> file 2>&1
1>> $root_dir/$log_out 2>> $root_dir/$log_err

(Reference)

thanks guys but nothing seems to work in this case.

I'm using the following statement for connection.

sqlplus -s $username/$password@$db << EOF 1>>$root_dir/result_.txt 2>>$root_dir/err.txt

What ever the result and the error both are always stored in result.txt
err.txt is created every time but remains blank!!!

Hi.

I would not expect it to work, as sqlplus does not write to standard error (2>...). Your best bet is probably to parse the one output file you do get, for errors.