Check output device is a terminal: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
m (→‎{{header|Wren}}: Small change to Wren and C file names.)
Line 637: Line 637:
{{trans|C}}
{{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.
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">/* Check_output_device_is_terminal.wren */
<syntaxhighlight lang="wren">/* Check_output_device_is_a_terminal.wren */


class C {
class C {
Line 711: Line 711:
WrenVM* vm = wrenNewVM(&config);
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* module = "main";
const char* fileName = "Check_output_device_is_terminal.wren";
const char* fileName = "Check_output_device_is_a_terminal.wren";
char *script = readFile(fileName);
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 731: Line 731:
{{out}}
{{out}}
<pre>
<pre>
$ ./Check_output_device_is_a_terminal
$ ./Check_output_device_is_terminal
Output device is a terminal = true
Output device is a terminal = true


$ ./Check_output_device_is_terminal > tmp
$ ./Check_output_device_is_a_terminal > tmp
$ cat tmp
$ cat tmp
Output device is a terminal = false
Output device is a terminal = false


$ ./Check_output_device_is_terminal | cat
$ ./Check_output_device_is_a_terminal | cat
Output device is a terminal = false
Output device is a terminal = false
</pre>
</pre>