我正在做我的第一个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将其解释为(正确!)一个问题,并引发一个错误。您可以使用catch
或try
来处理这些错误。
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...
}