luapipestdoutstdintty

Check if STDIN or STDOUT is a TTY in Lua


In C you have isatty(file_descriptor) and you can pass 0 as the file descriptor for STDIN and 1 for STDOUT.

How can I assert that in Lua?


Solution

  • I don't know of anything built-in but you could always shell out for a test with [ or tty (obviously somewhat non-portable) if you didn't want to use a C module that exposed isatty.

    C modules that expose isatty:

    1. lua-term
    2. luaposix

    there are probably others too.