how to overwrite, or delete the file, used by writefile() calls?

206 views Asked by At

I use the following to save screen output to a file

writefile("file.txt"),
tex(expression),
closefile()

The above sends the output of the tex() to the file automatically. which is all and well and what I want. (side-point: It also sends an annoying NIL line each time to the file, which I had to parse put later).

Now, when running the above code again, the file is appended to, which is not what I want. I want to either overwrite the file each time, or if there is a way to delete the file, so I can call delete on it before.

I looked at help and not able to find a command to delete a file, and I also see no option to tell writefile() to overwrite the file?

Is there an option or way around this? I am on windows 7, Maxima version: 5.36.1 Lisp: SBCL 1.2.7

1

There are 1 answers

0
Robert Dodier On BEST ANSWER

I guess you are trying to capture the output of tex into a file. If so, here are a couple of other ways to do it:

tex (expr, destination);

where destination is either a file name (which is appended) or a stream, as created by opena or openw and closed by close. By the way, destination could be false, in which case tex returns a string.

with_stdout (destination, tex (expr));

where again destination is either a file name (which is appended or clobbered, as determined by the global flag file_output_append) or a stream.

with_stdout could be useful if you want to mix in some output not generated by tex, e.g., print("% some commentary");.