Check output device is a terminal: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: test not e01) |
|||
Line 388: | Line 388: | ||
There is no explicit way (ie <tt>isatty()</tt>)to do this; however, if we ''assume'' that standard out ''is'' a terminal, we can check if the output stream has been redirected (presumably to something other than a terminal). |
There is no explicit way (ie <tt>isatty()</tt>)to do this; however, if we ''assume'' that standard out ''is'' a terminal, we can check if the output stream has been redirected (presumably to something other than a terminal). |
||
<lang Nemerle>def isTerm = System.Console.IsOutputRedirected;</lang> |
<lang Nemerle>def isTerm = System.Console.IsOutputRedirected;</lang> |
||
=={{header|Nim}}== |
|||
Using function "isatty" of standard module "terminal" which accepts a File as argument. |
|||
As we want to redirect stdout, we write the messages on stderr. |
|||
<lang Nim>import terminal |
|||
stderr.write if stdout.isatty: "stdout is a terminal\n" else: "stdout is not a terminal\n"</lang> |
|||
{{out}} |
|||
<pre>Command: ./check_output_dev |
|||
Result: stdout is a terminal</pre> |
|||
<pre>Command: ./check_output_dev >somefile |
|||
Result: stdout is not a terminal</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |