简体   繁体   中英

Passing variable from python to imagej macro

I am new to python. What I am trying to do is to pass a variable from python to imagej macro using subprocess.Popen or subprocess.call, but i am confused by how to form the arguments required. I have searched through all the post but have not gotten anywhere near.

I have try a few different ways like:

subprocess.Popen(["C://Users//user//Desktop//ij150-win-jre6//ImageJ.exe", "C://Users//user//Desktop//ij150-win-jre6//plugins//test.ijm"], stdin=PIPE, --p)
subprocess.Popen(["C://Users//user//Desktop//ij150-win-jre6//ImageJ.exe", "C://Users//user//Desktop//ij150-win-jre6//plugins//test.ijm"], p)
subprocess.Popen(["C://Users//user//Desktop//ij150-win-jre6//ImageJ.exe", "C://Users//user//Desktop//ij150-win-jre6//plugins//test.ijm", p])

Below is the code from python

import subprocess

p="test"

subprocess.Popen(["C://Users//name//Desktop//ij150-win-jre6//ImageJ.exe", "C://Users//name//Desktop//ij150-win-jre6//plugins//test.ijm"], stdin=PIPE, --p)

Below is the code from imagej

function testing(p)
{
    print (p);
}

I have tried the above few ways but keep getting errors like "positional argument follows keyword argument" and "'str' object has no attribute 'fileno'". I suspect it could be wrong coding on imagej side but i am not sure how. I tried just print (p) but an error occurs in imagej.

Basically i want the imagej macro to read the variable provided by python (in this case 'p') and then print out the variable in imagej. Can someone please help me with this?

Thank you.

After many tries and googling, i finally found the answer. the python code to call imagej program and script and also to pass variable to the script is as follows:

process = subprocess.Popen('imagej.exe --console -macro script.ijm variable', stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

in order for the script.ijm to receive the argument, the script have to have the line:

Input = getArgument();

Now i am trying to find out how to have the script.ijm output info to python.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM