I think this is the problem..

You have:
var %cmd = $remove($gettok($regml(1),1,45),])

which is 'remove all "]" characters from the text before the "-" character.' Try this:

var %cmd = $remove($gettok($regml(1),1,93),])

-genius_at_work