Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

output S.O.S.

5 views
Skip to first unread message

Scott Green

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

If anyone can help me with this, it'd be goddam excellent.

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.

David J Cooper Jr

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

Scott Green wrote:

> 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...


P. Srinivas

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

Scott Green (scott....@virgin.net) wrote:
: If anyone can help me with this, it'd be goddam excellent.

: 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

Steve Gonedes

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

Scott Green wrote:
>
> If anyone can help me with this, it'd be goddam excellent.
>
> 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 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.

Kevin Goodier

unread,
Mar 2, 1998, 3:00:00 AM3/2/98
to

Scott Green (scott....@virgin.net) says...

> If anyone can help me with this, it'd be goddam excellent.
>
> 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.


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/

Erik Naggum

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

* Scott Green

| 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.

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.

0 new messages