Check output device is a terminal: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Added two (2) examples for Lua) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 37:
stdout is not a tty.
</pre>
=={{header|C}}==
Line 65 ⟶ 66:
stdout is not tty
</pre>
<lang csharp>using System;▼
namespace CheckTerminal {▼
class Program {▼
static void Main(string[] args) {▼
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);▼
}▼
}▼
}</lang>▼
=={{header|C++}}==
Line 88 ⟶ 100:
return 0;
▲}</lang>
▲=={{header|C#|C sharp}}==
▲<lang csharp>using System;
▲namespace CheckTerminal {
▲ class Program {
▲ static void Main(string[] args) {
▲ Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
▲ }
▲ }
}</lang>
Line 181 ⟶ 182:
1
</lang>
=={{header|Go}}==
Line 230:
stdout is not tty
</pre>
=={{header|Javascript/NodeJS}}==▼
<lang js>node -p -e "Boolean(process.stdout.isTTY)"▼
true</lang>▼
=={{header|J}}==
Line 250 ⟶ 246:
But, correctness requires us to keep in mind that these will only be heuristics, and will sometimes be incorrect (hopefully not often enough to matter a lot...).
▲=={{header|Javascript/NodeJS}}==
▲<lang js>node -p -e "Boolean(process.stdout.isTTY)"
▲true</lang>
=={{header|Julia}}==
Line 368:
Other
</lang>
=={{header|Perl 6}}==▼
{{works with|Rakudo|2015.12}}▼
The .t method on a filehandle tells you whether it's going to the terminal. Here we use the note function to emit our result to standard error rather than standard out.▼
<pre>$ perl6 -e 'note $*OUT.t'▼
True▼
$ perl6 -e 'note $*OUT.t' >/dev/null▼
False</pre>▼
=={{header|PHP}}==
Line 398 ⟶ 390:
(terminal-port? (current-output-port))
</lang>
(formerly Perl 6)
▲{{works with|Rakudo|2015.12}}
▲The .t method on a filehandle tells you whether it's going to the terminal. Here we use the note function to emit our result to standard error rather than standard out.
▲<pre>$ perl6 -e 'note $*OUT.t'
▲True
▲$ perl6 -e 'note $*OUT.t' >/dev/null
▲False</pre>
=={{header|REXX}}==
{{works with|PC/REXX under DOS or in a DOS window under MS Windows}}
Line 438 ⟶ 440:
p STDOUT.isatty # => true
</lang>
=={{header|Rust}}==
<lang rust>/* Uses C library interface */
Line 475 ⟶ 478:
println("tty " + apply(true))
}</lang>
=={{header|Tcl}}==
To detect whether output is going to a terminal in Tcl, you check whether the <code>stdout</code> channel looks like a serial line (as those are indistinguishable from terminals). The simplest way of doing that is to see whether you can read the <tt>-mode</tt> or <code>-xchar</code> channel options, which are only present on serial channels:
|