[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: redirecting the output of print()
- From: Niccolo Medici <niccolomedici@...>
- Date: Thu, 21 Jun 2018 19:22:35 +0300
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).
The documentation for print() says it prints "to stdout", and the
documentation for io.output() says that it "opens the named file and
sets its handle as the default output file". So I don't undertand why
my code doesn't work.