lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 20.11.11 13:37, schrieb PooshhMao:
> Hi,
> 
> My program prints stuff to the console. Most of the time I use just
> print(), but in some cases I prefer to use io.write() and io.flush(),
> for example to show progress on an
> operation. The problem is that, when I do, the Lua script won't run
> anymore if not executed from a terminal. At any rate, there's little
> point in showing stuff in the terminal if it's not visible, so I suppose
> I would need to set the standard output to a file. So how can I
> determine if the script is run from a terminal or not?
> 
> I use LuaJIT on Kubuntu Linux, if that matters.

I C there is a function isatty() which you can use to determine if
standard output is a tty or not.  I don't know if the Lua posix modules
has this function, if not it should be easy to roll your own wrapper
around it.