Check input device is a terminal: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Promote to task, lots of examples, most of the concerns and controversy has been resolved) |
|||
Line 254: | Line 254: | ||
There is no explicit way (ie <tt>isatty()</tt>)to do this; however, if we ''assume'' that standard input ''is'' a terminal, we can check if the input 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 input ''is'' a terminal, we can check if the input stream has been redirected (presumably to something other than a terminal). |
||
<lang Nemerle>def isTerm = System.Console.IsInputRedirected;</lang> |
<lang Nemerle>def isTerm = System.Console.IsInputRedirected;</lang> |
||
=={{header|Nim}}== |
|||
Using function "isatty" of standard module "terminal" which accepts a File as argument. |
|||
<lang Nim>import terminal |
|||
echo if stdin.isatty: "stdin is a tty" else: "stdin is not a tty"</lang> |
|||
{{out}} |
|||
<pre>Command: ./check_input_dev |
|||
Result: stdin is a tty</pre> |
|||
<pre>Command: ./check_input_dev <somefile |
|||
Result: stdin is not a tty</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |