Quantcast

Running a Jython Script from the Command Prompt

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Running a Jython Script from the Command Prompt

MChapman
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running a Jython Script from the Command Prompt

Michael Entrup
Hi Mike,

the python doc [1] tells me that os.popen() is deprecated since version
2.6 and this was released about 9 years ago. Your problem does not have
to be related to this, but I would try to use the subprocess module.

At the forum there are a lot of topics about the headless mode [2].

Best regards
Michael


[1]: https://docs.python.org/2/library/os.html#os.popen
[2]: http://forum.imagej.net/search?q=--headless


On 14.02.2017 23:05, MChapman 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.com/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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running a Jython Script from the Command Prompt

ctrueden
In reply to this post by MChapman
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.
> com/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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running a Jython Script from the Command Prompt

ctrueden
> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running a Jython Script from the Command Prompt

MChapman
This post has NOT been accepted by the mailing list yet.
In reply to this post by ctrueden
Michael - I will look into the subprocess option...I remember trying it before and the os.popen was simple and worked well for my application, but I will revisit it now.

Curtis - "os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" -ij2 --headless --run "SomeScript.py"')  " had the same result of just opening the script.

"os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" --jython "SomeScript.py"')  " doesn't get any response from ImageJ at all.

Mike

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Running a Jython Script from the Command Prompt

MChapman
This post has NOT been accepted by the mailing list yet.
In reply to this post by ctrueden
Michael - I will look into the subprocess option...I remember trying it before and the os.popen was simple and worked well for my application, but I will revisit it now.

Curtis - "os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" -ij2 --headless --run "SomeScript.py"')  " had the same result of just opening the script.

"os.popen('"C:\Program Files\Fiji.app\ImageJ-win64.exe" --jython "SomeScript.py"')  " doesn't get any response from ImageJ at all.

Mike

Posting again because I stopped getting replies in my email and I can't get it to confirm if I post to the board...
Loading...