Tcl语言中,exec命令的返回值是所执行的外部命令的输出结果。如果命令的返回状态是非0值的话,则报告错误。下面的代码用于获取外部命令的返回状态代码:
set status 0 if {[catch {exec grep foo bar.txt} results]} { set details $::errorCode ;# [dict get $options -errorcode] if {[lindex $details 0] eq "CHILDSTATUS"} { set status [lindex $details 2] } else { set status -1 return -options $options -level 0 $results } }
Tcl中用open命令打开一个文件。如果文件名由字符'|'开始的话,则表示打开相应命令的管道输出或输入。
set fout [open "| mail" w] puts $fout "To: [email protected]" close $fout set fin [open "| ls" r] set text [read $fin] close $fin
TODO