问题
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