TCL/EXPECT自动化测试脚本实例五 --- 由文件中读取一行

王朝other·作者佚名  2007-02-23
窄屏简体版  字體: |||超大  

代码见下,比较简单,就不再分析了。调用实例见前面的文章。

#************************************************

# get a line from file, skip blank lines and

# comment lines, return the reading line in

# parameter 'line'.

#

# @PARAMS

# fd - file fd

# line - var used to return the line

#

# @RETURN

# return 1 if read successfully, otherwise 0

#************************************************

proc getLine {fd line} {

upvar $line ln

# read a line from fd

while {[set lineLen [gets $fd ln]] >= 0} {

# blank line

if { $lineLen == 0 } continue

# trim whitespace

set ln [string trim $ln]

if { [string length $ln] == 0 } continue

# skip comment

if { [string index $ln 0] == "#" } continue

# success

return 1

}

return 0

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航