예제 #1
0
 public void run() {
   try {
     clientProcess.waitFor();
   } catch (InterruptedException ie) {
   }
   parent.remove(client);
 }
 private void excute(String[] cmd) {
   try {
     Process ps = Runtime.getRuntime().exec(cmd);
     ps.waitFor();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #3
0
 protected static void cleanOutputs() {
   try {
     String cleanerScript = BASE_TESTING_DIR + "\\0000_clean_outputs.bat";
     Process process = Runtime.getRuntime().exec(cleanerScript);
     process.waitFor();
   } catch (IOException | InterruptedException e) {
     e.printStackTrace();
   }
 }
예제 #4
0
 public static int ensureNTServiceIsRunning(String serviceName, String service) throws Exception {
   ArrayList<String> serviceList = getRunningNTServices();
   if (serviceList == null) return -1; // not NT kernel?
   for (String svc : serviceList) {
     if (serviceName.equals(svc.trim())) return 0; // service already running
   }
   Process process = RUNTIME.exec(comSpec + "net start \"" + service + "\"");
   process.waitFor(); // wait for the process to complete
   int rc = process.exitValue(); // pick up its return code
   boolean success = (rc == 0);
   if (success) System.out.println("Successfully started service '" + serviceName + "'.");
   return (success ? 1 : -1);
 }
  @Override
  public ProcessConsoleFrame apply(final Process process) {
    log.info("Watching process " + process);

    try {
      SwingUtilities.invokeAndWait(
          new Runnable() {
            @Override
            public void run() {
              consoleFrame = new ProcessConsoleFrame(CONSOLE_NUM_LINES, true);
              consoleFrame.setProcess(process);
              consoleFrame.setVisible(true);
              MessageLog messageLog = consoleFrame.getMessageLog();
              messageLog.consume(process.getInputStream());
              messageLog.consume(process.getErrorStream());
            }
          });

      // Wait for the process to end
      process.waitFor();
    } catch (InterruptedException e) {
      // Orphan process
    } catch (InvocationTargetException e) {
      log.log(Level.WARNING, "Unexpected failure", e);
    }

    log.info("Process ended, re-showing launcher...");

    // Restore the launcher
    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            new LauncherFrame(launcher).setVisible(true);

            if (consoleFrame != null) {
              consoleFrame.setProcess(null);
              consoleFrame.requestFocus();
            }
          }
        });

    return consoleFrame;
  }
예제 #6
0
 private void startProcess(List<String> command) {
   ProcessBuilder processBuilder = new ProcessBuilder(command);
   DarkMod darkMod = DarkMod.getInstance();
   DarkModUI ui = darkMod.getUI();
   try {
     if (ui != null) {
       ui.setVisible(false);
       ui.dispose();
     }
     Process process = processBuilder.start();
     StreamRedirectFactory.createInputToOutputRedirect(process.getInputStream(), System.out);
     StreamRedirectFactory.createInputToOutputRedirect(process.getErrorStream(), System.err);
     StreamRedirectFactory.createInputToOutputRedirect(System.in, process.getOutputStream());
     System.exit(process.waitFor());
   } catch (Exception exception) {
     exception.printStackTrace();
     System.exit(-1);
   }
 }
예제 #7
0
  protected boolean executeUploadCommand(Collection commandDownloader) throws RunnerException {
    firstErrorFound = false; // haven't found any errors yet
    secondErrorFound = false;
    notFoundError = false;
    int result = 0; // pre-initialized to quiet a bogus warning from jikes

    String userdir = System.getProperty("user.dir") + File.separator;

    try {
      String[] commandArray = new String[commandDownloader.size()];
      commandDownloader.toArray(commandArray);

      String avrBasePath;

      if (Base.isLinux()) {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/");
      } else {
        avrBasePath = new String(Base.getHardwarePath() + "/tools/avr/bin/");
      }

      commandArray[0] = avrBasePath + commandArray[0];

      if (verbose || Preferences.getBoolean("upload.verbose")) {
        for (int i = 0; i < commandArray.length; i++) {
          System.out.print(commandArray[i] + " ");
        }
        System.out.println();
      }
      Process process = Runtime.getRuntime().exec(commandArray);
      new MessageSiphon(process.getInputStream(), this);
      new MessageSiphon(process.getErrorStream(), this);

      // wait for the process to finish.  if interrupted
      // before waitFor returns, continue waiting
      //
      boolean compiling = true;
      while (compiling) {
        try {
          result = process.waitFor();
          compiling = false;
        } catch (InterruptedException intExc) {
        }
      }
      if (exception != null) {
        exception.hideStackTrace();
        throw exception;
      }
      if (result != 0) return false;
    } catch (Exception e) {
      String msg = e.getMessage();
      if ((msg != null)
          && (msg.indexOf("uisp: not found") != -1)
          && (msg.indexOf("avrdude: not found") != -1)) {
        // System.err.println("uisp is missing");
        // JOptionPane.showMessageDialog(editor.base,
        //                              "Could not find the compiler.\n" +
        //                              "uisp is missing from your PATH,\n" +
        //                              "see readme.txt for help.",
        //                              "Compiler error",
        //                              JOptionPane.ERROR_MESSAGE);
        return false;
      } else {
        e.printStackTrace();
        result = -1;
      }
    }
    // System.out.println("result2 is "+result);
    // if the result isn't a known, expected value it means that something
    // is fairly wrong, one possibility is that jikes has crashed.
    //
    if (exception != null) throw exception;

    if ((result != 0) && (result != 1)) {
      exception = new RunnerException(SUPER_BADNESS);
      // editor.error(exception);
      // PdeBase.openURL(BUGS_URL);
      // throw new PdeException(SUPER_BADNESS);
    }

    return (result == 0); // ? true : false;
  }