如何检查 stdin/stdout 是否连接到 tcl 中的终端
How to check if stdin/stdout are connected to a terminal in tcl
我希望我的脚本可以通过 cron 交互运行。在后一种情况下,如果某些环境变量未初始化并且不提示用户输入它们,它应该只记录并退出。在 C 中,我会通过 _isatty(_fileno(stdin))
检查它,但如何在 tcl 中执行此操作? tcl wiki 建议 set interactive [ expr ! [ catch { exec /bin/sh -c { [ -t 0 ] }}]]
,但由于显而易见的原因,这不适用于 Windows。
[dict exists [fconfigure stdin] -mode]
也不起作用,这就是我从终端 -blocking 1 -buffering line -buffersize 4096 -encoding cp1251 -eofchar -translation auto
得到的
我有个坏消息。我检查了代码,以及 Windows 控制台通道类型处理程序 doesn't declare any custom options(与非 Windows 不同,其中控制台是串行通道,因此提供 -mode
和其他选项).因此,无法进行检测。
我希望我的脚本可以通过 cron 交互运行。在后一种情况下,如果某些环境变量未初始化并且不提示用户输入它们,它应该只记录并退出。在 C 中,我会通过 _isatty(_fileno(stdin))
检查它,但如何在 tcl 中执行此操作? tcl wiki 建议 set interactive [ expr ! [ catch { exec /bin/sh -c { [ -t 0 ] }}]]
,但由于显而易见的原因,这不适用于 Windows。
[dict exists [fconfigure stdin] -mode]
也不起作用,这就是我从终端 -blocking 1 -buffering line -buffersize 4096 -encoding cp1251 -eofchar -translation auto
我有个坏消息。我检查了代码,以及 Windows 控制台通道类型处理程序 doesn't declare any custom options(与非 Windows 不同,其中控制台是串行通道,因此提供 -mode
和其他选项).因此,无法进行检测。