All I want to do (I'm sure it's v. simple, really) is get
Lisp to send its output to a file instead of (or as well as)
the screen. The literature states that all you need to do is
put (format t "my output text"), replacing t with the desired
destination. But it ain't workin'. It just doesn't want to know.
Can someone PLEASE help me? Thanking U in advance.
> All I want to do (I'm sure it's v. simple, really) is get
> Lisp to send its output to a file instead of (or as well as)
> the screen. The literature states that all you need to do is
> put (format t "my output text"), replacing t with the desired
> destination. But it ain't workin'. It just doesn't want to know.
>
> Can someone PLEASE help me? Thanking U in advance.
You need some decent literature such as Graham's ANSI Common Lisp.
(with-open-file (outstream "/tmp/spew.txt"
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format outstream "my output text"))
--
David J Cooper Jr Genworks International
dcoo...@genworks.com http://www.genworks.com
...Embracing an Open Systems Approach to Knowledge-based Engineering...
: All I want to do (I'm sure it's v. simple, really) is get
: Lisp to send its output to a file instead of (or as well as)
: the screen. The literature states that all you need to do is
: put (format t "my output text"), replacing t with the desired
: destination. But it ain't workin'. It just doesn't want to know.
You need to create a STREAM for the file and pass it to
FORMAT for output. Here is a simple example:
(with-open-file (str "myfile.lisp" :direction :output :if-exists :overwrite)
;; now the varibale STR is bound to a OUTPUT STREAM which
;; is obtained by opeing a connection to the file "myfile.lisp"
(format str "Hello world!~%") ; output goes to the file
(format str "Whatever you want~%") ; output goes to the file
)
WITH-OPEN-FILE automatically closes the stream after its body is processed.
Alternatively, you can do the opening and closing yourself.
> (setq *myfile-stream* (open "myfile.lisp" :direction :output ))
#<output stream ...>
> (format *myfile-stream* "Hello World!~%")
Hello World
> (close *myfile-stream*)
#< closed strem ... >
hope this helps.
Srini
You can make a broadcast stream that does I/O to more than one stream at
a time.
(with-open-file (out "output.txt" :direction :output)
(let ((outstream (make-broadcast-stream out *standard-output*)))
(format outstream "~2&Hello!")))
I don't know if a broadcast-stream would work with *terminal-io*, it
probably would; but I have no way of testing that right now.
In addition to what everyone has said about the FORMAT command, you may
also want to look at DRIBBLE. Where they got the name baffles me, but
us it like:
(dribble "output.txt")
And EVERYTHING that would normally be written to the screen will be
written to the file name you specify. It's just like a terminal
capture.. To turn it off, just do
(dribble)
------------->
Kevin Goodier
bk...@cec.wustl.edu
http://students.cec.wustl.edu/~bkg2/
in addition to the many excellent answers, also note that you can set or
bind *STANDARD-OUTPUT* to some other stream object and still use T in
FORMAT to write to it. don't know if this is what you really want.
#:Erik
--
God grant me serenity to accept the code I cannot change,
courage to change the code I can, and wisdom to know the difference.