启动脚本出错:子进程异常退出

时间:2016-09-05 00:26:57

标签: tcl tk

正在处理我的第一个tcl / tk项目,但每当我运行脚本时,它都会显示我的错误

Error in startup script: child process exited abnormally
while executing
"exec which [string tolower $css]"
(procedure "::Ui::scriptSettings" line 16)
invoked from within
"::Ui::scriptSettings $::Ui::scriptSettings"
(procedure "::Ui::Ui" line 15)
invoked from within
"::Ui::Ui"
(file "./init.tcl" line 266)

它总是在这一行

$installationPath insert 0 [exec which [string tolower $css]]

$ css是/ usr / bin文件夹中存在的路径

这是触发错误的程序

foreach css $::Ui::CSS {
    set cssScriptLabel [labelframe $settingsCssFrame.cssLabel$i -text $css]
    set optionalArgument [label $cssScriptLabel.optArg$i -text "Optional Arguments"]
    set optArgEntry [entry $cssScriptLabel.optArgEntry$i]

    set outFileLabel [label $cssScriptLabel.outFile$i -text "OutFile/OutDir"]
    set outFileEntry [entry $cssScriptLabel.outFileEntry$i]
    set installationPathLabel [label $cssScriptLabel.installLabel$i -text "Intallation Path"]
    set installationPath [entry $cssScriptLabel.installPath$i]
    $installationPath delete 0 end
    $installationPath insert 0 [exec which [string tolower $css]]
    grid $cssScriptLabel -pady 5 -columnspan 1
    grid $optionalArgument $optArgEntry -sticky news
    grid $outFileLabel $outFileEntry -sticky news
    grid $installationPathLabel $installationPath
    incr i;
}

我想要做的是用$ css

的路径名替换输入框中的文本

1 个答案:

答案 0 :(得分:2)

听起来which调用未能找到该程序。当它找不到它时,它以非零退出代码退出,并且Tcl将(正确!)解释为一个问题,并引发错误。您可以使用catchtry处理这些错误。

try {
    $installationPath insert 0 [exec which [string tolower $css]]
} trap CHILDSTATUS {} {
    # No such program; recover here...
}

改为使用catch(其中包含所有错误,包括语法错误等等):

if {[catch {
    $installationPath insert 0 [exec which [string tolower $css]]
}]} {
    # No such program; recover here...
}