Tcl If构造中的破坏条件
嗨,我正在使用这段代码在TCL中插入管道。当此条件Tcl If构造中的破坏条件,tcl,Tcl,嗨,我正在使用这段代码在TCL中插入管道。当此条件[获取$pipe line]>=0失败时,请任何人告诉我。 例如:只有当[get$pipe line]为负数时,此操作才会失败 在我的例子中,它永远不会返回负数,测试引擎永远挂起 set pipeline [open "|Certify.exe filename" "r+"] fileevent $pipeline readable [list handlePipeReadable $pipeline] fconfigure $pipeline
[获取$pipe line]>=0
失败时,请任何人告诉我。
例如:只有当[get$pipe line]
为负数时,此操作才会失败
在我的例子中,它永远不会返回负数,测试引擎永远挂起
set pipeline [open "|Certify.exe filename" "r+"]
fileevent $pipeline readable [list handlePipeReadable $pipeline]
fconfigure $pipeline -blocking 0
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
从:
如果指定了varName,并且由于文件结尾或非阻塞模式下的数据不足而在varName中返回空字符串,则返回计数为-1
从:
如果指定了varName,并且由于文件结尾或非阻塞模式下的数据不足而在varName中返回空字符串,则返回计数为-1
获取
命令(当给定一个变量来接收行时)在出现小错误时返回一个负数。有两种情况:
获取
后,eof
命令(应用于通道)将报告一个真实值chan pending
)获得挂起字节的数量)。只有当通道处于非阻塞模式时,您才会看到这一点(因为否则,获取
将无限期等待)。在这种情况下,fblocked
命令(应用于通道)将返回true如果另一个命令只产生部分输出,或者对缓冲做了一些奇怪的事情,那么您可以得到一个永久阻塞的管道。更可能是使用双向管道,例如您正在使用的,
certifite
命令可能正在等待您关闭另一端。你能用只读的吗?双向正确地与流程交互有许多复杂性!(例如,您可能希望将管道的输出缓冲模式设为无缓冲,fconfigure$pipeline-buffering none
)当gets
命令(在给定一个变量以接收行时)在出现小错误时返回负数。有两种情况:
获取
后,eof
命令(应用于通道)将报告一个真实值chan pending
)获得挂起字节的数量)。只有当通道处于非阻塞模式时,您才会看到这一点(因为否则,获取
将无限期等待)。在这种情况下,fblocked
命令(应用于通道)将返回true如果另一个命令只产生部分输出,或者对缓冲做了一些奇怪的事情,那么您可以得到一个永久阻塞的管道。更可能是使用双向管道,例如您正在使用的,
certifite
命令可能正在等待您关闭另一端。你能用只读的吗?双向正确地与流程交互有许多复杂性!(例如,您可能希望将管道的输出缓冲模式设为非缓冲模式,fconfigure$pipeline-buffering none
)您的脚本运行完全正常。使用设置管道[open“| du/usr”“r+”进行检查
而不是您的管道,包括放置“Line:$Line”
以检查结果。所以很明显,certifite
命令中存在一些问题。您是否可以共享您的命令、如何在终端上使用以及如何与exec
一起使用
################### edited by Drektz
set pipeline [open "|du /usr" "r+"]
fileevent $pipeline readable [list handlePipeReadable $pipeline]
fconfigure $pipeline -blocking 0
proc handlePipeReadable {pipe} {
if {[gets $pipe line] >= 0} {
# Managed to actually read a line; stored in $line now
################### included by Drektz
puts "Line: $line"
} 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
你的脚本运行得很好。使用
设置管道[open“| du/usr”“r+”进行检查
而不是您的管道,包括放置“Line:$Line”
以检查结果。所以很明显,certifite
命令中存在一些问题。您是否可以共享您的命令、如何在终端上使用以及如何与exec
一起使用
################### edited by Drektz
set pipeline [open "|du /usr" "r+"]
fileevent $pipeline readable [list handlePipeReadable $pipeline]
fconfigure $pipeline -blocking 0
proc handlePipeReadable {pipe} {
if {[gets $pipe line] >= 0} {
# Managed to actually read a line; stored in $line now
################### included by Drektz
puts "Line: $line"
} 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
请查找从命令提示符触发认证过程的方式,并给出打印语句以供理解。最后,进程挂起,控制权未转移回TCL。您可以在提到的CMDwith&screenshot中看到它。是否有解决问题的方法?您可以在提到的CMDwith&screenshot中看到它。是否有解决问题的方法?请在运行时查看问题在exec可执行参数的帮助下&请查看在exec可执行参数的帮助下运行时出现的问题&也在底部发布了vwait::donepie我假设认证程序仅为文本。
是否设置输出[exec certified.exe文件名];输入$output
提供正确的输出?打开|…r+
表示危险。双向管道有很多可能失败的方式,例如另一端决定缓冲比您想要的更长的时间,或者在输入端关闭之前不生成任何输出…嗨,Glenn,在这里我将其称为文件名。但是在我们的项目中,对于Certify(工具)我们将传递一组参数来触发脚本除了这个Glenn,当我使用exec命令调用外部进程(在我的例子中是certifite)时,TCL脚本(测试引擎)脚本将永远挂起。这就是为什么,尝试在bott处使用一个也发布了vwait::donepie的管道