首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TCL-8.5中使用Spawn-Expect机制

在TCL-8.5中使用Spawn-Expect机制
EN

Stack Overflow用户
提问于 2019-06-28 13:32:24
回答 1查看 96关注 0票数 0
代码语言:javascript
复制
set pipeline [open "|Certify.exe args" "r"]
fconfigure $pipeline -blocking false
fconfigure $pipeline -buffering none
fileevent $pipeline readable [list handlePipeReadable $pipeline]


proc handlePipeReadable {pipe} {
if {[gets $pipe line] >= 0} {
# Managed to actually read a line; stored in $line now
} elseif {[eof $pipe]} {
    # Pipeline was closed; get exit code, etc.
    if {[catch {close $pipe} msg opt]} {
        set exitinfo [dict get $opt -errorcode]
    } else {
        # Successful termination
        set exitinfo ""
    }
    # Stop the waiting in [vwait], below
    set ::donepipe $pipe
} else {
    puts ""
    # Partial read; things will be properly buffered up for now...
    }
}

vwait ::donepipe

我尝试过在TCL代码中使用管道。但出于某些原因,我想将其转换为Spawn Expect机制。但我正在努力解决这个问题,并在这样做的时候遇到一些问题。有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2019-06-28 20:20:09

Expect使得使用模式非常不同,它使用一种不同的方式与包装的程序交互,这更像是交互式使用的工作方式(它阻止了一整类与缓冲相关的bug,我怀疑这可能就是您要遇到的问题)。正因为如此,将东西转换过来并不是一个即兴的改变。下面是在一个简单案例中使用的基本模式:

代码语言:javascript
复制
package require Expect

# Note: different words become different arguments here
spawn Certify.exe args

expect "some sort of prompt string"
send "your input\r";   # \r is *CARRIAGE RETURN*
expect "something else"
send "something else\r"
expect eof

close

当你可以设置超时,一次等待多个东西,等待模式和文字字符串等时,真正的复杂性出现了。但是从普通的Tcl做同样的事情(甚至忽略缓冲问题)是更多的工作。在几乎所有其他语言中,它也几乎总是更多的工作。

请注意,Expect不执行GUI自动化。只有命令行程序。GUI自动化是一个复杂得多的主题。

不可能对可能要做的事情给出一般性的描述,因为这在很大程度上取决于Certify.exe程序实际做了什么,以及如何交互地使用它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56801395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档