【问题标题】:Run common TCL script on Windows and Linux在 Windows 和 Linux 上运行常用的 TCL 脚本
【发布时间】:2015-04-17 20:27:20
【问题描述】:

我是 TCL 的新手。如何跨 Windows 和 Linux 运行通用 tcl 脚本?我想先检查平台类型,然后调用适当的 tcl proc。

【问题讨论】:

标签: tcl


【解决方案1】:

是的,杰克逊。基本上,我想知道我的脚本在什么操作系统上运行,例如,

set OS [lindex $tcl_platform(os) 0]
if { $OS == "Windows" } {
    perform this ...
} else {
    perform that ...
}

【讨论】:

  • 通常只需检查 $tcl_platform(platform) 就足够了,因为最新版本的 Windows 彼此足够相似,并且大多数 Unix 都足够接近。
【解决方案2】:

您可以从查看 tcl_platform 数组开始。在我的(Windows)机器上,这会报告以下内容:

% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine)   = intel
tcl_platform(os)        = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform)  = windows
tcl_platform(threaded)  = 1
tcl_platform(tip,268)   = 1
tcl_platform(tip,280)   = 1
tcl_platform(user)      = username
tcl_platform(wordSize)  = 4

在 Unix 系统上,os 和 osVersion 将是 uname -suname -r 各自报告的值。如果您需要更复杂的东西,那么平台包可能是您的最佳选择!

【讨论】:

    【解决方案3】:

    Tcl 中的大多数东西在 Windows 和 Unix 上都是一样的;隐藏差异的绝大多数细节。处理其余的:

    • 使用file join 而不是在两者之间连接/
    • 使用file nativename 将文件名传递给子进程。
    • 小心load;它的功能一点也不便携。
    • info 命令有一些有用的东西,例如 Tcl 解释器的名称 (info nameofexecutable),因此您可以在子进程中轻松地启动解释器。
    • 有些东西是不可移植的(例如,访问 Windows 注册表)。

    也有一些细微的差别,但您必须指导我们如何处理您的程序,以便我们知道哪些位很重要(例如,Windows 会在可执行文件运行时锁定可执行文件,而 Unix 则不会。 t;有时这会改变事情)。

    【讨论】:

      猜你喜欢
      • 2015-02-18
      • 1970-01-01
      • 2012-03-05
      • 2016-02-02
      • 1970-01-01
      • 2015-08-24
      • 2017-03-28
      • 2010-12-02
      • 1970-01-01
      相关资源
      最近更新 更多