Check output device is a terminal: Difference between revisions

Content added Content deleted
m (Fix Perl 6 -> Raku calling conventions)
(Add COBOL)
Line 101: Line 101:
return 0;
return 0;
}</lang>
}</lang>

=={{header|COBOL}}==
Works with GnuCOBOL.

<lang cobol> *>
*> istty, check id fd 0 is a tty
*> Tectonics: cobc -xj istty.cob
*> echo "test" | ./istty
*>
identification division.
program-id. istty.

data division.
working-storage section.
01 rc usage binary-long.

procedure division.
sample-main.

call "isatty" using by value 0 returning rc
display "fd 0 tty: " rc

call "isatty" using by value 1 returning rc
display "fd 1 tty: " rc upon syserr

call "isatty" using by value 2 returning rc
display "fd 2 tty: " rc

goback.
end program istty.</lang>

DISPLAY for fd 1 is directed to SYSERR to get some output during the various trials.

{{out}}
<pre>prompt$ cobc -xj istty.cob
fd 0 tty: +0000000001
fd 1 tty: +0000000001
fd 2 tty: +0000000001
prompt$ echo "test" | ./istty
fd 0 tty: +0000000000
fd 1 tty: +0000000001
fd 2 tty: +0000000001
prompt$ echo "test" | ./istty >/dev/null
fd 1 tty: +0000000000
prompt$ echo "test" | ./istty 2>/dev/tty
fd 0 tty: +0000000000
fd 1 tty: +0000000001
fd 2 tty: +0000000001
prompt$ echo "test" | ./istty 2>/dev/null
fd 0 tty: +0000000000
fd 2 tty: +0000000000</pre>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==