首页 > 解决方案 > Eclipse RCP cmd 提示处理程序

问题描述

我正在开发和应用 eclipse rcp 框架(3.0)。我想在运行菜单中创建一个 Eclipse RCP 命令,将 shell 命令发送到 windows cmd 提示符。

如何通过事件触发它?

public class RunCmd extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

        // I need to get runtime exec
    }

}

标签: cmdeclipse-plugineclipse-rcp

解决方案


用于执行 Windows 命令提示符的示例代码。
有不同的方法可用于检查过程是否正确执行

public class SampleHandler extends AbstractHandler {

        public static final String ID = "com.example.views.play";
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {

            String command = "adb shell input key 26";
            try
            {
                Process process = Runtime.getRuntime().exec(command);
            } catch (IOException e)
            {
                e.printStackTrace();
            }

            return null;
        }
    }

推荐阅读