Check input device is a terminal: Difference between revisions

Content added Content deleted
No edit summary
(Dialects of BASIC moved to the BASIC section.)
Line 35: Line 35:
stdin is not a tty.
stdin is not a tty.
</pre>
</pre>

=={{header|BaCon}}==
=={{header|BASIC}}==
==={{header|BaCon}}===
<syntaxhighlight lang="freebasic">terminal = isatty(0)
<syntaxhighlight lang="freebasic">terminal = isatty(0)
PRINT terminal</syntaxhighlight>
PRINT terminal</syntaxhighlight>
Line 49: Line 51:
prompt$ ./istty <<<"testing"
prompt$ ./istty <<<"testing"
0</pre>
0</pre>

==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
Open Cons For Input As #1
' Open Cons abre los flujos de entrada (stdin) o salida (stdout) estándar
' de la consola para leer o escribir.

If Err Then
Print "Input doesn't come from tt."
Else
Print "Input comes from tty."
End If
Close #1
Sleep
</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}}==
=={{header|C}}==
Use <code>isatty()</code> on file descriptor to determine if it's a TTY. To get the file descriptor from a <code>FILE*</code> pointer, use <code>fileno</code>:
Use <code>isatty()</code> on file descriptor to determine if it's a TTY. To get the file descriptor from a <code>FILE*</code> pointer, use <code>fileno</code>:
Line 153: Line 189:
C:\test < in.txt
C:\test < in.txt
Input doesn't come from tty.</pre>
Input doesn't come from tty.</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Open Cons For Input As #1
' Open Cons abre los flujos de entrada (stdin) o salida (stdout) estándar
' de la consola para leer o escribir.

If Err Then
Print "Input doesn't come from tt."
Else
Print "Input comes from tty."
End If
Close #1
Sleep
</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|Go}}==
=={{header|Go}}==