Anonymous user
Check output device is a terminal: Difference between revisions
Check output device is a terminal (view source)
Revision as of 12:27, 15 February 2024
, 3 months ago→{{header|Standard ML}}
m (→{{header|Wren}}: Minor tidy) |
imported>Regattaguru |
||
(One intermediate revision 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="wren">/*
class C {
Line 711 ⟶ 714:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 731 ⟶ 734:
{{out}}
<pre>
$ ./Check_output_device_is_a_terminal
Output device is a terminal = true
$ ./
$ cat tmp
Output device is a terminal = false
$ ./
Output device is a terminal = false
</pre>
|