Check output device is a terminal: Difference between revisions

m (Automated syntax highlighting fixup (second round - minor fixes))
imported>Regattaguru
 
(2 intermediate revisions by one other user not shown)
Line 602:
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">val stdoutRefersToTerminal : bool = Posix.ProcEnv.isatty Posix.FileSys.stdout</syntaxhighlight>
=={{header|Swift}}==
<syntaxhighlight lang="swift">print(isatty(STDOUT_FILENO) != 0 ? "TTY" : "Not TTY" )</syntaxhighlight>
 
=={{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:
Line 637 ⟶ 640:
{{trans|C}}
As there is currently no way to obtain this information via Wren CLI, we instead embed a Wren script in a C application and ask the host program to get it for us.
<syntaxhighlight lang="ecmascriptwren">/* check_output_device_is_terminalCheck_output_device_is_a_terminal.wren */
 
class C {
Line 711 ⟶ 714:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "check_output_device_is_terminalCheck_output_device_is_a_terminal.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 731 ⟶ 734:
{{out}}
<pre>
$ ./Check_output_device_is_a_terminal
$ ./check_output_device_is_terminal
Output device is a terminal = true
 
$ ./check_output_device_is_terminalCheck_output_device_is_a_terminal > tmp
$ cat tmp
Output device is a terminal = false
 
$ ./check_output_device_is_terminalCheck_output_device_is_a_terminal | cat
Output device is a terminal = false
</pre>
 
=={{header|zkl}}==
On Unix, check to see if stdout's st_mode is a character device.
Anonymous user