【问题标题】:run command continuously in background using tcl使用 tcl 在后台连续运行命令
【发布时间】:2015-03-17 18:16:40
【问题描述】:

我正在使用 tcl/expect 测试以太网交换机。我想每 2 秒在后台重复运行一些测试工具。输出可以忽略。

也就是说,我想做以下事情: 有一个代码块一遍又一遍地重复以下代码,直到从另一块代码中停止:

 exec { $myCommand }
 sleep $sleepDuration

$myCommand 可以是列表或字符串,无论哪种更方便。 $sleepDuration 是一个数字。

在另一个代码块中,我将执行正常操作,包括生成进程并与它们交谈或与现有连接进行交互。

tcl 有可能吗?我在 VMWare 的 Debian Linux 6 上运行。代码不需要移植到其他平台。

我曾尝试使用手表,但不知道如何执行以下操作:

exec {watch $myCommand}
switch to an already connected process
interact with it
switch to watch
send "\x03"

【问题讨论】:

    标签: linux tcl expect


    【解决方案1】:

    在最简单的情况下,命令快速运行,您使用every 模式:

    proc every {delay script} {
        uplevel #0 $script
        after $delay [info level 0]
    }
    every 2000 {exec $yourCommand $yourArgument &}
    

    然后,只要您为 Tcl 事件循环提供服务,该命令就会每 2 秒运行一次(== 2000 毫秒)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 2021-01-10
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 2017-09-19
      • 2021-06-19
      相关资源
      最近更新 更多