Re: detect batch mode in Tcl shell



Donal K. Fellows wrote:
Donald Arseneau wrote:
"Gerald W. Lester" <Gerald.Lester@xxxxxxx> writes:
What tcl_interactive tells you is are you running wish/tclsh if you invoked
it with a startup script or not.
A modern standard test for "batch" mode is isatty(stdin), which
seems to correspond ro what tcl_interactive reports.

Not really. If tclsh is running a script, it isn't interactive even if
stdin is a TTY. :-) Instead, the real equivalent to that check (in 8.4)
is to examine the list of options returned by [fconfigure stdin], which
will look different (on unix at least) if the terminal is a TTY.

However, since the original questioner was really asking about loading
Tk, the best check is probably whether a DISPLAY environment variable
has been set. If not, you're definitely not interactive, and a [package
require Tk] will fail. No idea how to port this conceptual check to
systems not using X11 for display.

Unless he is on MS Windows.


--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.



Relevant Pages

  • Re: looking for thread about backup using ssh -T
    ... If stdin is not a tty, ... allocation, and that only happens if stdin is a tty. ... incantation because it has less opportunity to seem magic or be treated ...
    (Fedora)
  • Re: tty question
    ... no access to tty. ... stty: stdin isn't a terminal ... This differs from having a connection to a pseudo tty ... which is connected to the standard input and standard output in that you ...
    (comp.unix.shell)
  • Re: Problem with popen() under FreeBSD v5.2.1 (long post)
    ... so this version works because the command's stdout becomes the main ... >tty if you run it interactively w/o redirection. ... > - read a line from stdin ...
    (comp.unix.bsd.freebsd.misc)
  • Re: /dev/stdin .... ?
    ... > with OpenSSH's SFTP program to transfer files among hosts. ... /proc/self/0 is not going to always be linked to the tty. ... to fix sftp to do what most portable programs do... ... as a special case for stdin... ...
    (comp.unix.tru64)
  • Re: Null dereference errors in the kernel
    ... > implemented a checker that finds potential null dereference errors and ... > sample reports below. ... broken interface if it provided the possibility of a NULL tty to work ...
    (Linux-Kernel)