Run program.exe from eclipse plugin project

邮差的信 提交于 2019-12-04 05:56:47

问题


I am writing an eclipse-plugin witch run program.exe. I have added program.exe to plugin jar file. How can a execute this program?

public class Handler extends AbstractHandler {
    public Object execute(ExecutionEvent event) throws ExecutionException {
        Runtime.getRuntime().exec(/*What should I write here*/);
        return null;
    }
}

回答1:


You can't run the program.exe from inside the plugin jar, so it needs to be extracted. In your plugin use:

Bundle bundle = Platform.getBundle("plugin id");

URL url = FileLocator.find(bundle, new Path("relative path to program"), null);

url = FileLocator.toFileURL(url);

This will find the program in the plugin jar and extract it to a temporary location (done by FileLocator.toFileURL).




回答2:


You should just execute the program like you would in cmd, but now specify the whole path of the programs location.

Runtime.getRuntime().exec("C:\\your\\path\\program.exe");

In the Oracle documentation of the Runtime class you can see the acceptable inputs in exec().



来源:https://stackoverflow.com/questions/31068876/run-program-exe-from-eclipse-plugin-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!