1

My intention is to develop an eclipse plugin (I will explain why I am sticking on to eclipse plugin.), that will execute a python script at a specific location (say C:\MyProject\testscript.py).

I am interested in getting responses, from those who have already tried out anything similar, on whether this approach will work.

Why Eclipse Plugin?
I am trying to listen to a notification from a Server. Although the server exposes Plain java APIs, the listening mechanism is not provided as plain java api. But using the eclipse plugins provided by the server, I can see the notifications in the eclipse UI.

asked Jan 22, 2014 at 21:32

2 Answers 2

2

Yes,it is possible

Sample code snippet

// Python script "test.py" is executed from an eclipse plugin

public class SampleHandler extends AbstractHandler {

/**
 * The constructor.
 */
public SampleHandler() {
}
/**
 * the command has been executed, so extract extract the needed information
 * from the application context.
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
 MessageDialog.openInformation(
 window.getShell(),
 "First",
 "Hello, Eclipse world");
 try
 {
 Runtime r = Runtime.getRuntime();
 String pythonScriptPath = "D:\\python-samples\\test.py";
 Process p = r.exec("python " + pythonScriptPath);
 BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));
 String line = "";
 while((line = bfr.readLine()) != null) {
 // display each output line form python script
 System.out.println(line);
 }
 }
 catch (Exception e)
 {
 String cause = e.getMessage();
 if (cause.equals("python: not found"))
 System.out.println("No python interpreter found.");
 }
 return null;
}

}

answered Jan 24, 2014 at 23:08
Sign up to request clarification or add additional context in comments.

Comments

1

I suggest trying to use Jython to bridge from Java (the Eclipse plugin) to your Python. See also Calling Python in Java? (and possibly Invoking python from Java and/or How to execute Python script from Java?)

answered Jan 22, 2014 at 21:45

1 Comment

Thanks E-Riz. I would try it out, and share the feedback here.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.