[Solved] Issue running scripts from the command line with Fiji

Hi all,

I want to run a script in headless mode. I have an up-to-date version of Fiji on Mac OS X 10.11.6 (my development machine) and linux64 (a cluster) and followed the instructions here:

Running

/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run hello.py "Mr Kraken"

on the Mac leads to the following error

Error while executing the main() method of class 'net.imagej.Main':
java.lang.IllegalArgumentException: Invalid character at index 4
	at org.scijava.sjep.Position.die(Position.java:70)
	at org.scijava.sjep.ExpressionParser$ParseOperation.parsePostfix(ExpressionParser.java:210)
	at org.scijava.sjep.ExpressionParser.parsePostfix(ExpressionParser.java:113)
	at org.scijava.sjep.eval.AbstractEvaluator.evaluate(AbstractEvaluator.java:87)
	at org.scijava.parse.DefaultParseService$ItemsList.parseItems(DefaultParseService.java:109)
	at org.scijava.parse.DefaultParseService$ItemsList.<init>(DefaultParseService.java:77)
	at org.scijava.parse.DefaultParseService.parse(DefaultParseService.java:63)
	at org.scijava.parse.DefaultParseService.parse(DefaultParseService.java:58)
	at org.scijava.run.console.RunArgument.handle(RunArgument.java:79)
	at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
	at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:81)
	at org.scijava.AbstractGateway.launch(AbstractGateway.java:95)
	at net.imagej.Main.launch(Main.java:62)
	at net.imagej.Main.main(Main.java:68)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
	at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
	at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)

Running this on the linux64 doesn’t work either. No error message is printed and the command never finishes.

On the Mac, I somehow manage to get away by using

/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run hello.py "name='Mr Kraken'"

However, these doesn’t change the frozen state on the linux64.

Any help would be appreciated!

Best wishes,
Tom

1 Like

Welcome to the forum, @tvercaut. And sorry for your troubles.

The SciJava parameter parsing was recently rewritten to use our new more powerful SciJava expression parser. But this introduced some additional requirements on the syntax here. Specifically, string literals must now be enclosed in either single or double quotation marks, rather than written bare. So your instinct to write:

/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run hello.py "name='Mr Kraken'"

is right on. And that should work in Linux as well, hopefully.

Furthermore, there now seems to be some issue with writing only comma-separated values in some circumstances. Therefore, I have updated the Scripting Headless wiki page to always recommend using the key=value pair syntax, since it is generally more safe & explicit anyway.

I tested the updated instructions on both OS X 10.11 as well as Ubuntu Linux 12.04.5 LTS, and the program runs successfully including terminating and returning to the command line within a couple of seconds. If you experience otherwise, please follow up here. And see also this Troubleshooting topic if you want to investigate further.

1 Like

Many thanks @ctrueden! This led me to investigate a bit more the linux case where it seems that I was experiencing an unrelated issue. On linux, I had installed the no-jre version of ImageJ (thinking that the java version installed on the cluster would do). I was able to launch the GUI of ImageJ successfully so thought everything was fine. I have now installed the linux64 version and this fixes my hanging issues when using it in headless mode.

For the record, the java version on my cluster is “1.7.0_51”. Given that the version with the jre embedded works fine, I don’t plan to investigate the issue with the no-jre version further.

1 Like

:+1:

Note that these days, ImageJ2 and Fiji require Java 8. For details, see: