Check input device is a terminal: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Dialects of BASIC moved to the BASIC section.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 3 users not shown)
Line 67:
</syntaxhighlight>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
BeginCCode
if (isatty(fileno(stdin)))
NSLog( @"stdin is connected to a terminal" );
else
NSLog( @"stdin is NOT connected to a terminal" );
EndC
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
stdin is NOT connected to a terminal
</pre>
 
=={{header|C}}==
Line 189 ⟶ 172:
C:\test < in.txt
Input doesn't come from tty.</pre>
 
 
=={{header|Forth}}==
{{works with|gforth|0.7.3}}
In Gforth, the word "source-id" is used to determine the program source.
 
If you got a program file "source.f":
<syntaxhighlight lang="Forth">
: ?tty source-id if ." not " then ." from terminal" ; ?tty bye
</syntaxhighlight>
Then,
<syntaxhighlight lang="bash">gforth source.f</syntaxhighlight> in the shell will display:
{{out}}<pre>not from terminal</pre>
Then,
<syntaxhighlight lang="bash">gforth -e ': ?tty source-id if ." not " then ." from terminal" ; ?tty bye'</syntaxhighlight> will display:
{{out}}<pre>not from terminal</pre>
 
At Gforth prompt,
<syntaxhighlight lang="bash">: ?tty source-id if ." not " then ." from terminal" ; ?tty bye</syntaxhighlight> will display:
{{out}}<pre>from terminal</pre>
 
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
BeginCCode
if (isatty(fileno(stdin)))
NSLog( @"stdin is connected to a terminal" );
else
NSLog( @"stdin is NOT connected to a terminal" );
EndC
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
stdin is NOT connected to a terminal
</pre>
 
 
=={{header|Go}}==
Line 491 ⟶ 514:
 
if [ -t 0 ]
then echo "Input is NOT a terminal"
then
else echo "Input is NOT a terminal"
else
echo "Input is NOT a terminal"
fi</syntaxhighlight>
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin
 
System.print("Input device is a terminal? %(Stdin.isTerminal ? "Yes" : "No")")</syntaxhighlight>
Line 505 ⟶ 527:
Input device is a terminal? Yes
</pre>
 
=={{header|zkl}}==
On Unix, check to see if stdin's st_mode is a character device.
9,479

edits