Search code examples
tclstdoutstdin

How to check if stdin/stdout are connected to a terminal in tcl


I want my script to be runnable interactively and from cron. In the latter case it should just log and quit if some env variables are not initialized and not prompt the user for them. In C I would check it via _isatty(_fileno(stdin)), but how to do this in tcl? tcl wiki suggests set interactive [ expr ! [ catch { exec /bin/sh -c { [ -t 0 ] }}]], but this won't work on Windows for obvious reasons.

[dict exists [fconfigure stdin] -mode] doesn't work either, that's what I get from a terminal -blocking 1 -buffering line -buffersize 4096 -encoding cp1251 -eofchar -translation auto


Solution

  • I've got bad news. I've checked the code, and the Windows console channel type handler doesn't declare any custom options (unlike on non-Windows, where consoles are serial channels and so provide -mode and other options). As such, there's no way to do the detection.