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

Error in startup script: child process exited abnormally

我正在处理我的第一个 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

的路径名

听起来 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...
}