代码之家  ›  专栏  ›  技术社区  ›  Corv1nus

有没有办法将参数传递给TCL中使用eval source运行的脚本?

  •  0
  • Corv1nus  · 技术社区  · 16 年前

    我有一个脚本调用:

     eval source \{$scriptfile\}
    

    其中$scriptfile是另一个TCL脚本。有没有办法把参数传递给脚本?我想做一些类似的事情:

    set sampleData "ID=14678934"
    eval source \{$scriptfile\} $sampleData 
    

    我知道这是不允许的,但是,有没有一种方法可以将数据传递给正在使用eval source执行的脚本?

    2 回复  |  直到 11 年前
        1
  •  5
  •   Trey Jackson    16 年前

    source script.tcl  ;# defines proc run_script_with_data
    run_script_with_data $data
    
        2
  •  3
  •   tonio    16 年前

    解决方案在 Tclers Wiki ,在以下文章中: source with args SrcFile .

    srcfile

    proc srcfile { filename args } {
      global argv
    
      set argv $args
      source $filename
    }
    

    这种方法的唯一缺点是它会修改 argv