Created by [CecilWesterhof]. Sometimes I need the output from a command. But not all commands return 0 on success. For example when you ask the status of a systemd service that is not running systemctl returns 3. But the command is still successful. Also the following line can be appended to the output: ====== child process exited abnormally ====== That is why I created the following proc: ====== proc getCleanOutput {command nonerrors} { try { set status [exec {*}${command}] } trap CHILDSTATUS {status opts} { set errorStr "\nchild process exited abnormally" set length [string length ${errorStr}] set retCode [lindex ${::errorCode} 2] if {[regexp "${errorStr}\$" ${status}]} { set status [string range ${status} 0 end-${length}] } if {! (${retCode} in ${nonerrors})} { error "'${command}' returned ${retCode}\n${status}" } } on error msg { error [format "'%s' gave unexpected error:\n%s" ${command} ${msg}] } return ${status} } ====== When the program returns a value other as 0 the trap handles what needs to be done. It removes the extra line if it is appended and then checks if the return code is an acceptable one. If not an error is raised, otherwise the output from the program is returned. If another error happens an error is raised. ---- As always: comments, tips and questions are appreciated. <>Utilities