public static void runScript(Script script, int scriptType) {
    if (scriptType == SHUTDOWN_SCRIPT) {
      try {
        script.process();
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
    } else {
      // Create a new Thread
      ScriptThread scriptThread = new ScriptThread(script, scriptType);

      // Run the Thread
      scriptThread.start();
    }
  }
예제 #2
0
    /**
     * Executes a script file without displaying it in the dialog.
     *
     * @param scriptFile The file to execute.
     */
    private void executeScriptFile(final File scriptFile) {
      final List<Pair<String, Object>> bindings = toPairList(m_bindings);

      final ScriptEngineManager manager = new ScriptEngineManager();

      final ScriptEngine engine =
          manager.getEngineByExtension(FileUtils.getFileExtension(scriptFile));

      final IScriptConsole console = new ConsoleWriter(new StringWriter());

      engine.getContext().setWriter(console.getWriter());

      bindings.add(new Pair<String, Object>("SCRIPT_CONSOLE", console));

      final ScriptThread thread = new ScriptThread(engine, scriptFile, bindings);

      CProgressDialog.showEndless(
          getOwner(), String.format("Executing '%s'", scriptFile.getAbsolutePath()), thread);

      if (thread.getException() != null) {
        CUtilityFunctions.logException(thread.getException());

        final String message = "E00108: " + "Script file could not be executed";
        final String description =
            CUtilityFunctions.createDescription(
                String.format(
                    "The script file '%s' could not be executed.", scriptFile.getAbsolutePath()),
                new String[] {
                  "The script file is in use by another program and can not be read.",
                  "You do not have sufficient rights to read the file",
                  "The script contains a bug that caused an exception."
                },
                new String[] {"BinNavi can not read the script file."});

        NaviErrorDialog.show(CScriptingDialog.this, message, description, thread.getException());
      }

      final IScriptPanel panel = (IScriptPanel) scriptTab.getSelectedComponent();

      panel.setOutput(console.getOutput());

      toFront();
    }