RosettaCodeData/Task/Check-output-device-is-a-terminal/Lua/check-output-device-is-a-terminal-1.lua
2023-07-01 13:44:08 -04:00

9 lines
288 B
Lua

local function isTTY ( fd )
fd = tonumber( fd ) or 1
local ok, exit, signal = os.execute( string.format( "test -t %d", fd ) )
return (ok and exit == "exit") and signal == 0 or false
end
print( "stdin", isTTY( 0 ) )
print( "stdout", isTTY( 1 ) )
print( "stderr", isTTY( 2 ) )