[Therion] Cross platform clean-up of system commands

Tarquin Wilton-Jones tarquin.wilton-jones at ntlworld.com
Fri Jan 17 16:50:44 CET 2025


Hi,

I am making a survey intended to be open source, which means it needs to 
compile everywhere, with minimal edits.

I use PDFtk for post-processing the PDF output, to include something 
else in the PDF. This generates some temp files, that I don't want to 
leave in the output folder, in case someone uses them by mistake, so I 
want to delete them.

Windows and Linux/Mac use different syntax, but "system" is a blunt 
tool, and does not seem to allow me to check which command to use:
system "del tempfile.pdf"
system "rm -f tempfile.pdf"

That generates an error message, and Therion thinks the file has failed 
to compile when it is actually unimportant.

Is it possible to code branch, like this:
if( windows ) {
	system "del tempfile.pdf"
} else {
	system "rm -f tempfile.pdf"
}

Is it possible to tell Therion not to consider the result of a "system" 
command when determining if compilation failed? Like using @system to 
ignore the output.

Alternatively, does someone have a syntax of command that works on any 
of these three platforms? This almost works, but Linux chucks junk into 
a file called "nul" (even though it is not using that command):
del tempfile.pdf 2>nul || rm -f tempfile.pdf 2>/dev/null

And yes, I know I could demand installation of Python and clean up that 
way, but it seems like such overkill when all I want to do is delete a 
temp file. I would rather not add yet another dependency.

Cheers,

Tarquin


More information about the Therion mailing list