Greetings ImageJ experts,
I’m attempting to pass multiple arguments to an ImageJ macro via the commandline. However, it seems that getArgument() can only be called once, and only accepts one argument from the CLI. Here’s a simple demonstration of what I mean: My macro file: dir = getArgument(); print("Processing directory: "+dir); range = getArgument(); print("Range: "+range); Then I execute it: $ ImageJ-linux64 -batch test.ijm foo bar No GUI detected. Falling back to headless mode. No GUI detected. Falling back to headless mode. Processing directory: foo Range: foo Unsupported format or not found Is there any way to do this nicely? I have considered using bash getopts to hack around this by editing the macro file in situ, but I’d really prefer a cleaner solution. This is for a batch processing environment, so using the GUI isn’t possible. Thanks much, Lincoln -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Lincoln,
you could try to have quotes around the list of argument, e.g. call ImageJ via ImageJ-linux64 -batch test.ijm "foo bar" This should give you everything into one argument, which you might retrieve via getArgument(); Then use 'split' to retrieve the individual arguments inside the macro. It will only work if you have no whitespace within any argument such as the directory path. I have not tried, however (I don't have Linux). Michael ________________________________________________________________ On Aug 3, 2015, at 17:07, Lincoln Bryant wrote: > Greetings ImageJ experts, > > I’m attempting to pass multiple arguments to an ImageJ macro via the commandline. However, it seems that getArgument() can only be called once, and only accepts one argument from the CLI. Here’s a simple demonstration of what I mean: > > My macro file: > > dir = getArgument(); > print("Processing directory: "+dir); > > range = getArgument(); > print("Range: "+range); > > Then I execute it: > > $ ImageJ-linux64 -batch test.ijm foo bar > No GUI detected. Falling back to headless mode. > No GUI detected. Falling back to headless mode. > Processing directory: foo > Range: foo > Unsupported format or not found > > Is there any way to do this nicely? I have considered using bash getopts to hack around this by editing the macro file in situ, but I’d really prefer a cleaner solution. > > This is for a batch processing environment, so using the GUI isn’t possible. > > Thanks much, > Lincoln > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you Michael!
Quoting the args and doing something like this seems to work: args = split(getArgument()," "); print(args[0]); Cheers, Lincoln > On Aug 3, 2015, at 10:31 AM, Michael Schmid <[hidden email]> wrote: > > Hi Lincoln, > > you could try to have quotes around the list of argument, e.g. call ImageJ via > ImageJ-linux64 -batch test.ijm "foo bar" > > This should give you everything into one argument, which you might retrieve via getArgument(); > > Then use 'split' to retrieve the individual arguments inside the macro. It will only work if you have no whitespace within any argument such as the directory path. > > I have not tried, however (I don't have Linux). > > Michael > ________________________________________________________________ > On Aug 3, 2015, at 17:07, Lincoln Bryant wrote: > >> Greetings ImageJ experts, >> >> I’m attempting to pass multiple arguments to an ImageJ macro via the commandline. However, it seems that getArgument() can only be called once, and only accepts one argument from the CLI. Here’s a simple demonstration of what I mean: >> >> My macro file: >> >> dir = getArgument(); >> print("Processing directory: "+dir); >> >> range = getArgument(); >> print("Range: "+range); >> >> Then I execute it: >> >> $ ImageJ-linux64 -batch test.ijm foo bar >> No GUI detected. Falling back to headless mode. >> No GUI detected. Falling back to headless mode. >> Processing directory: foo >> Range: foo >> Unsupported format or not found >> >> Is there any way to do this nicely? I have considered using bash getopts to hack around this by editing the macro file in situ, but I’d really prefer a cleaner solution. >> >> This is for a batch processing environment, so using the GUI isn’t possible. >> >> Thanks much, >> Lincoln >> -- >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |