[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How can I find out whether my program is running interactively?
- From: HyperHacker <hyperhacker@...>
- Date: Fri, 4 Nov 2011 00:15:43 -0600
On Fri, Nov 4, 2011 at 00:07, Dirk Laurie <email@example.com> wrote:
> I want my program to print out a message when io.stdout is a terminal,
> but not when it is a disk file. Current solution: write it to
> io.stderr, not io.stdout. Is there a better way?
Common solutions include using stderr if stdout is likely not to be a
terminal, or providing an argument to write to a file instead of
stdout (instead of redirecting), or using isatty() to check. I recall
there being a way to check whether your code is running in the Lua
console by checking the call traceback or some such, but I don't think
that's what you mean by running interactively.
Sent from my toaster.