the following works fine:
(set 'out-buff "Now is the time to try men's souls")
(write-file "soulTest1.txt" out-buff)
but this doesn't:
(set 'out-buff "Now is the time to try men's souls")
(set 'out-file-handle (open "soulTest2.txt" "write"))
(write-file out-file-handle out-buff)
What's going on here? Many thanks.
I think out-file-handle is in fact an integer:
(integer? out-file-handle)
;-> true
but write-file wants a string...
Yes, (write-file <str-file-name> <str-content>) is for writing an entire file in one shot.
Use (write-buffer <int-handle> <str-content>) if you want to write to a file handle, which also must be closed after writing.
(set 'out-buff "Now is the time to try men's souls")
(set 'out-file-handle (open "soulTest2.txt" "write"))
(write-buffer out-file-handle out-buff)
(close out-file-handle)
Most of the time write-file does the job much easier in one statement. Use write-buffer only for bigger files, or when writing to a string buffer for fast destructive string appending (see manual).
Lutz
Thanks; that clarifies.
Tim