1

This question is a follow up of

Running Jython script from terminal with parameter

@KarlderKaefer

In brief, I'd like to call ImageJ from command-line to execute Python scripts, which take parameters as input and parse with getopt(). As stated in the above link there are two ways to script and call:

  1. The classical Python way with sys.argv
> imagej --headless --console JythonScript.py param1

JythonScript.py:

import sys
program_name = sys.argv[0]
paramvalue1  = sys.argv[1]
  1. The Jython specific way with # @String etc.
> imagej --ij2 --headless --console --run JythonScript_2.py 'param1=value'

JythonScript_2.py:

# @String param1

The Jython (second) way worked for me but when I try the "classical Python" (first) way, I got:

Error while executing the main() method of class 'org.python.util.jython':
java.lang.UnsatisfiedLinkError: org.scijava.jython.shaded.org.fusesource.jansi.internal.CLibrary.init()V
        at org.scijava.jython.shaded.org.fusesource.jansi.internal.CLibrary.init(Native Method)
        at org.scijava.jython.shaded.org.fusesource.jansi.internal.CLibrary.<clinit>(CLibrary.java:43)
        at org.scijava.jython.shaded.org.fusesource.jansi.AnsiConsole.wrapOutputStream(AnsiConsole.java:48)
        at org.scijava.jython.shaded.org.fusesource.jansi.AnsiConsole.<clinit>(AnsiConsole.java:38)
        at org.python.jline.AnsiWindowsTerminal.detectAnsiSupport(AnsiWindowsTerminal.java:57)
        at org.python.jline.AnsiWindowsTerminal.<init>(AnsiWindowsTerminal.java:27)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.python.jline.TerminalFactory.getFlavor(TerminalFactory.java:211)
        at org.python.jline.TerminalFactory.create(TerminalFactory.java:102)
        at org.python.jline.TerminalFactory.get(TerminalFactory.java:186)
        at org.python.jline.TerminalFactory.get(TerminalFactory.java:192)
        at org.python.jline.console.ConsoleReader.<init>(ConsoleReader.java:243)
        at org.python.util.JLineConsole.install(JLineConsole.java:107)
        at org.python.core.Py.installConsole(Py.java:1744)
        at org.python.core.PySystemState.initConsole(PySystemState.java:1269)
        at org.python.core.PySystemState.doInitialize(PySystemState.java:1119)
        at org.python.core.PySystemState.initialize(PySystemState.java:1033)
        at org.python.core.PySystemState.initialize(PySystemState.java:989)
        at org.python.core.PySystemState.initialize(PySystemState.java:984)
        at org.python.util.jython.run(jython.java:263)
        at org.python.util.jython.main(jython.java:142)
        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:498)
        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)

I never learned Java so couldn't figure out what's gonig on.. So anyone please help me? Thank you!

System information Win10.0.17134 (Edu) x64 Fiji ImageJ 2.0.0-rc-69/1.52p Java 1.8.0_172 (x64) Windows PowerShell 5.1.17134.858 running in ConEmu 191012 preview

  • The `#@` parameters (your second way) are not at all Jython-specific, but specific to the SciJava/ImageJ framework. Keep in mind that you start your script using the ImageJ launcher, not a `python` executable. I don't know how you'd expect the first way to work. I recommend asking this on https://forum.image.sc – Jan Eglinger Jan 07 '20 at 13:40
  • Since the second way works, means ImageJ can parse parameters and send "param1 param2" to Python script. So, the question is whether in the first way it can send those params as well. I can certainly post question on forum.image – Mythracis W Jan 07 '20 at 13:49

0 Answers0