我想在每次 运行 tcl 脚本时隐藏 windows 终端?

I want to hide the windows terminal every time I run a tcl script?

我正在使用 Windows 8.1,并且我正在 运行ning 一个检查文件差异的 tcl 脚本:

package require twapi
proc diff {file1 file2} {
    set f1 [open $file1 "rb"]
    set f2 [open $file2 "rb"]
    try {
        while 1 {
            if {[read $f1 4096] ne [read $f2 4096]} {
                return 0
            } elseif {[eof $f1]} {
                # The same if we got to EOF at the same time
                return [eof $f2]
            } elseif {[eof $f2]} {
                return 0
            }
        }
    } finally {
        close $f1
        close $f2
    }
}

我需要在后台运行这个程序,但每次我运行它,它都会打开一个windows终端。我尝试使用 vbs 脚本并且有效:

CreateObject("Wscript.Shell").Run "diff.tcl",0,True

但我需要将参数从另一个程序传递给 diff.tcl,因此 运行ning 作为 vbs 脚本没有用。

问题

多纳尔说的。

具体来说,您安装的 Windows™ 据说 设置为将 tclsh.exe 与 运行 文件关联 .tcl 在他们的名字中扩展。 (一种学习什么的方法 关联是 运行ning assoc.exe; also see ftype.exe).

tclsh.exe(名字源于"The Tcl Shell")是 使用 so-called "console subsystem" 编译的应用程序 标志设置(特殊 header 中的标志包含 Windows™ 上可执行文件的元信息)。 当 OS 运行s 这样的应用程序时,它会注意到它需要 一个控制台,因此它生成一个控制台,然后 运行s 应用程序 在里面。

解决方案

  • 尝试使用 WScript.ShellRun 方法 object 并将 0 作为第二个参数传递以隐藏 创建 window;有关更多信息,请参阅 this

  • Tcl 附带另一个解释器,称为 wish.exe ("The Windowed Shell" 的端口号)不同 来自 tclsh.exe 事实上它有 Tk 自动可用(加载)。

    您可能希望使用 wish.exe 显式 运行 您的脚本 并将脚本的路径名作为参数传递给它。

    您可能需要使用 wm withdraw . 作为脚本中的第一个命令来隐藏由 Tk 创建的主要 window。

您是否考虑过将结果输出到临时文件并让下游的任何内容查找该文件?然后,您可以使用键入脚本的 VBS 方法。这很混乱,但它会起作用。