Login  Register

Re: Running a Jython Script from the Command Prompt

Posted by ctrueden on Feb 15, 2017; 10:06am
URL: http://imagej.273.s1.nabble.com/Running-a-Jython-Script-from-the-Command-Prompt-tp5018100p5018104.html

> I think that this flag "-jython" is valid.

Sorry, I meant: I think that this flag '-jython' is _not_ valid.


On Wed, Feb 15, 2017 at 10:05 AM, Curtis Rueden <[hidden email]> wrote:

> Hi Mike,
>
> > os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" -jython --run
> "SomeScript.py"')
>
> I think that this flag "-jython" is valid. There is an undocumented flag
> "--jython" with two dashes which the ImageJ Launcher supports, but like all
> the language-specific flags (e.g., --javascript, --clojure, etc.), it was
> added before we switched to the unified SciJava script framework. So it
> actually launches Java quite differently than using "--run", and it does
> not make sense to mix the two.
>
> The current way, according to the Scripting Headless [1] page, is to use:
>
>   ImageJ-win64.exe --ij2 --headless --run "SomeScript.py"
> 'sigma=5,label="GFP"'
>
> where the "sigma" etc. argument is a list of key/value pairs corresponding
> to the @ parameters of your script [2]. (Of course, if you have no such
> parameters, you do not need to pass anything after the name of your script.)
>
> Like you said, Jython+Windows+headless has (had?) a bug [3] which prevents
> it from working. However, since that bug report, we have upgraded from
> Jython 2.5.3 to 2.7.0—so it would actually be awesome if you could test now
> whether it works. And if so, we can close that bug and remove the warning
> from the wiki.
>
> You could also try the old "--jython" flag and see if it works for you,
> but in that case I would try something like:
>
>   ImageJ-win64.exe --jython "SomeScript.py"
>
> And you will not be able to use the SciJava @ parameters.
>
> Regards,
> Curtis
>
> [1] http://imagej.net/Scripting_Headless
> [2] http://imagej.net/Script_Parameters
> [3] https://github.com/imagej/imagej/issues/114
>
> --
> Curtis Rueden
> LOCI software architect - https://loci.wisc.edu/software
> ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
> Did you know ImageJ has a forum? http://forum.imagej.net/
>
>
> On Tue, Feb 14, 2017 at 10:05 PM, MChapman <[hidden email]>
> wrote:
>
>> Hello again,
>>
>> I have a set of image processing codes that go between Python and ImageJ
>> by
>> calling macro scripts from Python through the command prompt.  One of
>> these
>> calls looks like:
>>
>> os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" --headless -macro
>> "SomeScript.ijm"')
>>
>> In attempting to integrate "Register Virtual Stack Slices" the only way
>> that
>> I could figure out how to script it to work autonomously was with a Jython
>> script.  The script works fine on its own, but when I try to call it from
>> Python it won't execute, it just opens up the script in the script editor
>> instead of executing.  The call looks like this:
>>
>> os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" --headless -jython
>> "SomeScript.py"')
>>
>> I saw on the wiki that there is a known bug with jython and running
>> headless, so I tried:
>>
>> os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" -jython
>> "SomeScript.py"')
>> os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" -jython --run
>> "SomeScript.py"')
>>
>> but neither worked.
>>
>> Any advice on how to get this to execute properly?
>>
>> Thanks!
>> Mike
>>
>>
>>
>>
>> --
>> View this message in context: http://imagej.1557.x6.nabble.c
>> om/Running-a-Jython-Script-from-the-Command-Prompt-tp5018100.html
>> Sent from the ImageJ mailing list archive at Nabble.com.
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html