[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newbie question: redirect stdout?
- Subject: Re: newbie question: redirect stdout?
- From: Liam Gumley <Liam.Gumley(at)ssec.wisc.edu>
- Date: Wed, 22 Sep 1999 12:50:29 -0500
- Newsgroups: comp.lang.idl-pvwave
- Organization: Space Science and Engineering Center, University of Wisconsin-Madison
- References: <andreask-2209991126030001@a119101.n1.vanderbilt.edu>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:16670
"Andreas V. Kadavanich" wrote:
> I'm running IDL 5.2.1 on a PowerMac
>
> I am running a batch program which takes about 5 hours per iteration (so I
> don't want to sit there watching) and generates a lot of output (mostly
> diagnostic messages) to stdout.
>
> I would like to log this output to a file, preferably by redirecting
> stdout (and stderr) to a file. I am stumped as to how to accomplish this
> within IDL short of changing all my print statements to explicitly write
> to a file (which wouldn't help with IDL generated messages).
On UNIX systems, you can use standard input and output, e.g.
% idl < input > output
but since you're on a Mac, this doesn't help.
One approach is to change your PRINT statements to PRINTF, and use the
standard output logical unit number (-1) when you want output to the log
window (IDL reserves the logical unit numbers 0, -1, -2 for stdin,
stdout, stderr). Here's an example:
PRO MYPRO, OUTFILE=OUTFILE
;- Check output file keyword
if n_elements(outfile) eq 0 then begin
;- No output file specified, so send output to stdout
outlun = -1
endif else begin
;- Output file was specified, so open it
openw, outlun, outfile, /get_lun
endelse
;- Print startup message
printf, outlun, 'Program started at ', systime(1)
;*** Use PRINTF instead of PRINT in your program ***
;- Print finish message
printf, outlun, 'Program finished at ', systime(1)
;- Close the output file if necessary
if outlun gt 0 then free_lun, outlun
END
For more information, consult the online help:
IDL> ? logical unit numbers
It is true that this won't re-direct any error messages from IDL to the
output file. But messages from IDL are most likely to be either
compilation messages or fatal error messages, and you'll see these in
the command log window easily because all other output is going to a
file. If you want to get really tricky, you can trap the IDL errors
yourself. See David Fanning's tip at
http://www.dfanning.com/tips/catch_trace.html
Cheers,
Liam.
--
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
http://cimss.ssec.wisc.edu/~gumley