TCL/EXPECT自动化测试脚本实例五 --- 由文件中读取一行
2006-05-30 10:31
686 查看
代码见下,比较简单,就不再分析了。调用实例见前面的文章。
#************************************************
# 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
}
#************************************************
# 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
}
相关文章推荐
- TCL/EXPECT自动化测试脚本实例六 --- SNMP community长度测试
- TCL/EXPECT自动化测试脚本实例二 --- 主程序
- TCL/EXPECT自动化测试脚本实例七 --- 构造报文测试
- TCL/EXPECT自动化测试脚本实例
- TCL/EXPECT自动化测试脚本实例三 --- 全局变量
- TCL/EXPECT自动化测试脚本实例四 --- 批命令执行
- TCL/EXPECT自动化测试脚本实例七 --- 构造报文测试
- TCLEXPECT自动化测试脚本实例
- shell脚本:一次读取文件的一行,并输出
- 利用Shell脚本循环读取文件中每一行的方法详解
- shell脚本,每次读取文件的一行,逐行读取并处理
- shell脚本中一次读取文件中的一行
- 实现BIN文件数据读取的TCL脚本分析
- shell脚本:一次读取文件的一行【转】
- 读取文件的每一行内容并输出 的shell脚本实现
- TCL/EXPECT自动化测试脚本
- python读取csv文件并把文件放入一个list中脚本实例
- Tcl脚本:从文件读入一行并处理的框架
- shell脚本:一次读取文件的一行【转】
- shell脚本,每次读取文件的一行,逐行读取并处理