且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行一个tcl脚本的多个实例

更新时间:2023-11-22 21:44:16

可以通过以下几种方法进行存档:

There are several options to archive this:

foreach hostname $hosts {
    exec log.tcl $hostname &
}

这就像bash解决方案.

This is like the bash solution.

package require Thread
set pool [tpool::create]
set jobs {}
foreach hostname $hosts {
    lappend jobs [tpool::post -nowait $pool [list apply {{host} {
        set argv0 log.tcl
        set argv [list $host]
        source $argv0
    } $hostname]]
}
while {[llength $jobs]} {
     tpool::wait $pool $jobs jobs
}

请注意,的问题不能很好地与线程.

Note that expect does not work nicely with threads.

关于从多个脚本写入同一文件的另一个问题:这取决于.如果您具有POSIX兼容系统,并使用a打开文件,则可能会起作用.

For the other question regarding writing to the same file from multiple scripts: It depends. If you have a POSIX compliant system and open the files with a, then it might work.