I want to redirect the output of print() to a file of my choosing.
(I know I can do "$ lua program.lua > output.txt", but I need to
create several output files. My program is already written and I don't
want to modify it too much.)
I tried this:
But this doesn't work (on both Lua 5.2 and 5.3): it creates an empty
file named "out.txt" but keeps sending the output to the terminal (I'm
using Linux, BTW).
You can write a small C library to call dup2() to redirect stdout to a file, if you are using Linux.