Check output device is a terminal: Difference between revisions

Add Haskell
(→‎{{header|Rust}}: Updated to the Rust 1.2.0)
(Add Haskell)
Line 112:
> hello | cat
Who are you? You're not a terminal.
</pre>
 
=={{header|Haskell}}==
 
<lang haskell>module Main where
 
-- requires the unix package
-- https://hackage.haskell.org/package/unix
import System.Posix.Terminal (queryTerminal)
import System.Posix.IO (stdOutput)
 
main :: IO ()
main = do
istty <- queryTerminal stdOutput
putStrLn (if istty
then "stdout is tty"
else "stdout is not tty")
</lang>
 
{{out}}
 
<pre>$ runhaskell istty.hs
stdout is tty
$ runhaskell istty.hs | cat
stdout is not tty
</pre>
 
Anonymous user