Actually, the stdout and stderr are not lost but they won't go in the spool file.
Given the script echo.sql
:
spool sql.out
select 1 from dual ;
!echo 1
!invalid command
spool off
If you launch your script from a shell as so :
sqlplus *connect string* @echo.sql > host.out 2> host.err
You will get the output from your sql command in sql.out
, the output from echo in host.out
and the error message in host.err
. If you're launching your script non interactively -from a cron or something- you'll have to capture stdout/stderr as you would do any other non sql*plus script.
Edit regarding comment
With the option SET TERMOUT ON
in the script file you will have the output of your sql commands both in the spool file and stdout.
So finally, if you want everything in one file you can call your script as so :
sqlplus *connect string* @echo.sql &>echo.log
You will still have the output of just the sql in the spool file.