when using ij-macro commands I struggled too to get things running…
Also if you want to run it headless, you cannot use the open command, since it will want to create an image display.
My suggestion would be to go for something like groovy to script this. An outline would look like
img = IJ.openImage('path/to/image.tif');
classifier = new WekaSegmentation()
res = classifier.applyClassifier(img, 0, false)
Sorry for not helping to debug, but I think switching the language will actually be easier.