情况是我需要使用某个命令调用工具,当工具完成运行时,它会生成exit 0状态。更准确地说,它说:
退出状态0
我想使用此退出状态0来执行我的下一个命令。我的意思是我想等到工具运行完成并返回退出0状态。伪代码:
run this tool command
wait until exit 0 status is generated by above command>
do the following
实际代码。
@run {incr i ; set ET_WORKDIR [lindex $argv $i]
set COPY_ET_WORKDIR "exec cp -pRf ${ET_WORKDIR} ET_WORKDIR"
puts "Copying the ${ET_WORKDIR} inside $env(PROJECT_WDIR_PATH) workarea"
eval $COPY_ET_WORKDIR
set run_et "exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg &"
lsc_msg "I" "ATPG analysis has been started!!!"
eval $run_et
if [info exist EXIT STATUS 0]
{set setup "exec mkdir $env(PROJECT_WDIR_PATH)/logs/${logdate}"
eval $setup
set setupcopy "exec cp -pRf $env(PROJECT_WDIR_PATH)/ET_WORKDIR/testresults/logs/* $env(PROJECT_WDIR_PATH)/logs/$logdate/."
eval $setupcopy
exit 0
}
}
答案 0 :(得分:0)
您正在执行的执行当前正在后台执行,因为您已将&
放在
set run_et "exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg &"
如果您将其更改为:
set run_et "exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg"
Tcl将等待命令完成运行,然后继续执行脚本。您可以使用以下方式获取输出:
set run_et "exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg"
set et_output [eval $run_et]
请注意,在这种情况下,实际上将其视为好的风格:
set et_output [exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg]
警告!如果et
产生非零退出代码或写入标准错误,exec
将抛出({{ 1}}能够)错误。最好的处理方式因catch
正在做的事情而有所不同,但通常有点像这样:
et
或者这(Tcl 8.6):
if {[catch {exec et -e $env(PROJECT_WDIR_PATH)/ET_WORKDIR/runet.atpg} et_output]} {
puts "Oh no! Things went wrong! Error message is '$et_output'"
exit 1
}