Wrong argument parsing in headless mode



Dear All,

I have a strange mistake:
When i run this script in Image J it opens a dialog, asks for a filename and writes the file as expected:

#@String filename
import os
from ij import IJ, ImagePlus

imp = IJ.createImage("Untitled", "8-bit random", 100, 100, 1)
IJ.saveAs(imp, "Tiff",file_path)

If i call it afterwards in headless and pass on an other filename, it still remembers what it did last and
writes a file with the wrong name??

I use the same synatax i would do at linux:

D:\\Fiji\Fiji.app\ImageJ.exe --ij2 --headless --run D:\\Fiji\Hello_file_.py 'filename="test.tif"'

Do you have any idea what might go wrong on windows 10, Fiji 1.51s Java 1.8.0_66 64 bit.

Thanks a lot & Kind regards



I suspect something might go wrong with the persisting of parameters: when you run a script, ImageJ remembers your last parameters and prefills them for you. But when you provide a parameter from the command line, this one should take preference over the persisted value, otherwise it’s a bug.

You might be able to work around the issue by adding (persist = false) to your script parameter:

#@String (persist = false) filename

Are you implying that the same issue does not occur when you run your script on Linux? That would indeed be strange…


Dear Jan,

Thanks a lot!

Yes the same issue does not occur in linux.
This, also makes sense to me.

Provided i pass on successfully the correct new value, it should not matter,
if ImageJ still knows the old value. It should be replaced, or?

After adding (persists=false) on Windows, no file is written at all.
If i remove --headless, i get this message:

“filename is required but unset”

suggesting that the Windows Fiji version has a bug, or my syntax (which works on linux) is wrong:

I call Fiji on command line by:

D:\\Fiji\Fiji.app\ImageJ.exe --ij2  --headless --run D:\\Fiji\Hello_file2_.py 'filename="test.tif"'

Thanks a lot & Kind regards



After doing some testing triggered by a related discussion:

… I noticed that there are some oddities with respect to quoting on the Windows Command Prompt. The options need to be either unquoted, or quoted with double-quotes ("); and to define string values inside key=value pairs, you need to use single quotes (').

So, your command:

ImageJ.exe --ij2  --headless --run D:\\Fiji\Hello_file2_.py 'filename="test.tif"'

… should instead be:

ImageJ.exe --ij2  --headless --run D:\\Fiji\Hello_file2_.py "filename='test.tif'"

Can you test if this works for you as well?


Dear Jan,

yes, now it works also on Windows.

(using as suggested: Double-quotes for the option and single quotes for the string)

ImageJ.exe --ij2 --headless --run D:\\Fiji\Hello_file2_.py "filename='test.tif'"

Thank you very much for your help!

Kind regards