Cross platform clean-up of system commands
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
I have a hackaround that basically allows code branching on Windows and Linux/Mac from within Therion's system command, so it always clears up temp files no matter what the platform is. Create a file called "rm.bat" in the .thconfig directory. Give it these contents: @echo off ::simulate the Linux rm command on Windows, since Therion's "system" ::command cannot cope with code branching for platforms if "%~2"=="" exit /b del "%~2" 2>nul Then the .thconfig can use this: system "rm -f deleteme-temp.pdf" On Linux, it uses the native "rm" command, and -f means it can silently ignore any temp files that didn't get created. On Windows, it uses rm.bat, and that redirects any error messages to nul. So Therion always considers it a success no matter what, and files get cleaned up no matter what. Anyone have anything better? (Did anyone cringe from that "solution"?) Cheers, Tarquin
I like your "rm.bat" hackaround, I would do the same :) Thomas On Sat, Jan 18, 2025 at 10:00 AM Tarquin Wilton-Jones via Therion <therion@speleo.sk> wrote:
I have a hackaround that basically allows code branching on Windows and Linux/Mac from within Therion's system command, so it always clears up temp files no matter what the platform is.
Create a file called "rm.bat" in the .thconfig directory. Give it these contents:
@echo off ::simulate the Linux rm command on Windows, since Therion's "system" ::command cannot cope with code branching for platforms if "%~2"=="" exit /b del "%~2" 2>nul
Then the .thconfig can use this: system "rm -f deleteme-temp.pdf"
On Linux, it uses the native "rm" command, and -f means it can silently ignore any temp files that didn't get created.
On Windows, it uses rm.bat, and that redirects any error messages to nul. So Therion always considers it a success no matter what, and files get cleaned up no matter what.
Anyone have anything better? (Did anyone cringe from that "solution"?)
Cheers,
Tarquin _______________________________________________ Therion mailing list Therion@speleo.sk https://mailman.speleo.sk/listinfo/therion
participants (2)
-
Tarquin Wilton-Jones -
Thomas Holder