在Windows和Linux上运行通用TCL脚本

发布于 2024-09-09 19:37:12 字数 75 浏览 5 评论 0原文

我是TCL的新人。如何在 Windows 和 Linux 上运行通用 tcl 脚本?我想首先检查平台类型,然后调用适当的 tcl 过程。

I am new to TCL. How can I run a common tcl script across Windows and Linux? I'd like to check platform type first and then call appropriate tcl proc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

二手情话 2024-09-16 19:37:12

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

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

Yup that worked, Jackson. Basically, I wanted to know what OS my script is running on, for example,

set OS [lindex $tcl_platform(os) 0]
if { $OS == "Windows" } {
    perform this ...
} else {
    perform that ...
}
终遇你 2024-09-16 19:37:12

您可以首先查看 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 报告的值。如果您需要更复杂的东西,那么平台包可能是您的最佳选择!

You can start by looking at the tcl_platform array. On my (windows) machine this reports the following:

% 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

On a Unix system the os and osVersion will be the values reported by uname -s and uname -r respectivley. If you need something more sophisticated then the platform package may be the way to go!

心凉 2024-09-16 19:37:12

Tcl 中的大多数功能在 Windows 和 Unix 上的工作方式相同;绝大多数存在差异的细节都被隐藏了。要处理其余部分:

  • 使用 file join 而不是在其间使用 / 连接。
  • 使用 file nativename 使文件名传递给子进程。
  • 小心加载;它所做的事情根本不可移植。
  • info 命令有一些有用的东西,例如 Tcl 解释器的名称 (info nameofexecutable),这样您就可以在子进程中轻松、可移植地启动解释器。
  • 有些东西就是不可移植的(例如,访问 Windows 注册表)。

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

Most things in Tcl work the same on Windows and Unix; the vast majority of details where there differences are hidden. To handle the rest:

  • Use file join instead of concatenating with / in between.
  • Use file nativename to make filenames to hand off to subprocesses.
  • Be careful with load; what it does is not at all portable.
  • The info command has some useful things, such as the name of the Tcl interpreter (info nameofexecutable) so you can start up interpreters in subprocesses portably and easily.
  • Some things just aren't portable (e.g., access to the Windows registry).

There are some subtle differences too, but you'll have to guide us with what you're doing with your program so that we can know what bits matter (e.g., Windows locks executables when they're running while Unix doesn't; sometimes that changes things).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文