tcl extra characters after close-brace

二次信任 提交于 2020-01-17 08:21:22

问题


i have this error Tcl error : extra characters after close-brace

proc exact {nick host handle channel text} {
global db_handle network;

set size exec curl -3 --ftp-ssl -k ftp://xxx:xxx@192.210.0.8:2300/source/ | grep \\.r | awk '{print $5}'| awk '{ SUM += $1} END { print SUM/1024/1024 }'

putnow "PRIVMSG #chnnel :source has $size"
}

回答1:


Per the exec(n) man page you need to replace single quotes with curly braces. You also need [] around exec to invoke it:

    set size [exec curl -s -3 --ftp-ssl -k {ftp://xxx:xxx@192.210.0.8:2300/source/} | grep \\.r | awk {{print $5}} | awk {{ SUM += $1} END { print SUM/1024/1024 }}]

That said, you don't need to invoke grep or awk at all. Everything you do with them here can be accomplished within the Tcl code:

proc exact {nick host handle channel text} {
    global db_handle network;

    set status 0
    set error [catch {
        set resp [exec curl -s -3 --ftp-ssl -k {ftp://xxx:xxx@192.210.0.8:2300/source/}]
    } results options]
    if {$error} {
        set details [dict get $options -errorcode]
        if {[lindex $details 0] eq "CHILDSTATUS"} {
             set status [lindex $details 2]
             putnow "PRIVMSG $channel :curl error $status"
        }
    }
    set size 0
    foreach line [split $resp \n] {
        if {[string match {*\\.r*} $line]} {
            incr size [lindex $line 4]
        }
    }

    putnow "PRIVMSG $channel :source has [expr {$size/1024/1024}]"
}

(I assume you've meant $channel rather than #chnnel.)



来源:https://stackoverflow.com/questions/27963431/tcl-extra-characters-after-close-brace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!