在Windows和Linux上运行通用TCL脚本
我是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这有效,杰克逊。基本上,我想知道我的脚本运行在什么操作系统上,例如,
Yup that worked, Jackson. Basically, I wanted to know what OS my script is running on, for example,
您可以首先查看 tcl_platform 数组。在我的(Windows)机器上,报告如下:
在 Unix 系统上,os 和 osVersion 将分别由
uname -s
和uname -r
报告的值。如果您需要更复杂的东西,那么平台包可能是您的最佳选择!You can start by looking at the tcl_platform array. On my (windows) machine this reports the following:
On a Unix system the os and osVersion will be the values reported by
uname -s
anduname -r
respectivley. If you need something more sophisticated then the platform package may be the way to go!Tcl 中的大多数功能在 Windows 和 Unix 上的工作方式相同;绝大多数存在差异的细节都被隐藏了。要处理其余部分:
file join
而不是在其间使用/
连接。file nativename
使文件名传递给子进程。加载
;它所做的事情根本不可移植。info
命令有一些有用的东西,例如 Tcl 解释器的名称 (info nameofexecutable
),这样您就可以在子进程中轻松、可移植地启动解释器。也存在一些细微的差异,但是您必须指导我们您对程序所做的事情,以便我们知道哪些位重要(例如,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:
file join
instead of concatenating with/
in between.file nativename
to make filenames to hand off to subprocesses.load
; what it does is not at all portable.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.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).