请参阅
http://wiki.tcl.tk/exec – 单击“显示讨论”按钮 – 这是一个非常详细的示例,说明如何完全按照您的要求进行操作.你需要的是捕获
原文链接:https://www.f2er.com/bash/383421.htmlset status [catch {exec script.bash} output] if {$status == 0} { puts "script exited normally (exit status 0) and wrote nothing to stderr" } elseif {$::errorCode eq "NONE"} { puts "script exited normally (exit status 0) but wrote something to stderr which is in $output" } elseif {[lindex $::errorCode 0] eq "CHILDSTATUS"} { puts "script exited with status [lindex $::errorCode end]." } else ...