Patrick,

maybe You find the bug by running that script with brakes (?"continue?" |get$x) on the strategic points in execution ... and for test purposes let the script show You all variables and values !
At least i would put a 'pause' in the calling cmd-file!
OR specify a '/d' in the command line = deug mode

Greetings

Jochen

_________________________