ITPub博客

首页 > Linux操作系统 > Linux操作系统 > TCL/EXPECT自动化测试脚本实例五 --- 由文件中读取一行

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

原创 Linux操作系统 作者:habug 时间:2008-07-09 14:10:58 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
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14780873/viewspace-374739/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-07-07

  • 博文量
    211
  • 访问量
    362632