Examples of ProcessExecutor


Examples of ProcessExecuting.ProcessExecutor

        BufferedWriter inputWriter = null; // пишет на вход программе
        BufferedReader testInputReader = null; // читает входной тест
        BufferedReader outputReader = null; // читает выход программы
        BufferedReader testOutputReader = null; // читает выходной тест
        BufferedReader errorReader = null; // читает стандартный вывод ошибок программы
        ProcessExecutor executor = new ProcessExecutor(
                program.getExecuteCmd(),
                program.getDirPath(), 3000); // выполняет программу
        boolean ise = false; // internal server error
        try {
            executor.execute(); // throws ProcessRunningException (невозможно в данном случае),
            // ProcessCanNotBeRunException (ошибка на сервере - нельзя запустить процесс)
            inputWriter = new BufferedWriter(
                    new OutputStreamWriter(executor.getOutputStream())); // throws ProcessNotRunningException
            testInputReader = new BufferedReader(
                    inputGenerator.getReader(testNumber));
            inputDataProcessor.process(inputWriter, testInputReader); // посылает данные на вход

            outputReader = new BufferedReader(
                    new InputStreamReader(executor.getInputStream())); // throws ProcessNotRunningException
            testOutputReader = new BufferedReader(
                    outputGenerator.getReader(testNumber));
            outputDataProcessor.process(outputReader, testOutputReader); // читает выходные данные, сравнивает с эталонными
        } catch (InputWriteException e) {
            // Если не работает запись на вход программы или чтение выхода
            // программы, то произошла ошибка времени выполнения.
        } catch (OutputReadException e) {
            // В блоке finally будет проверен код выхода программы.
        } catch (ProcessExecutingException ex) { // из executor.execute(), ошибка запуска программы
            throw new TestingInternalServerErrorException("Program running error: " + ex);
        } catch (TestingInternalServerErrorException e) { // при обработке входных/выходных данных, тесты не найдены или не могут быть прочитаны
            ise = true;
            throw e;
        } catch (ComparisonFailedException e) { // при обработке выходных данных, может быть ошибка времени выполнения
            throw new UnsuccessException(e.getMessage());
        } finally {
            if (executor.isRunning()) { // если программа была запущена, надо ее завершить
                // читает стандартный вывод ошибок
                message = new StringBuffer();
                try {
                    errorReader = new BufferedReader(new InputStreamReader(executor.getErrorStream())); // throws ProcessNotRunning - невозможно
                    String line;
                    while ((line = errorReader.readLine()) != null) { // throws IOException
                        message.append(line + "\n");
                    }
                } catch (Exception e) { // ошибка ввода/вывода
                    e.printStackTrace();
                } finally {
                    FileOperator.close(errorReader);
                }
                // ждем завершения программы
                if (executor.quietStop()) {
                    System.err.println("Process was running for " + executor.getWorkTime());
                    System.err.println("Program in test case " + testNumber + " exited with code " + executor.getCode());
                    if (!ise) { // если тесты были найдены и прочитаны
                        // код также будет выполняться, если была ComparisonFailedException - может быть ошибка времени выполнения
                        if (executor.isOutOfTime()) {
                            throw new TestingTimeLimitExceededException("Program is out of time");
                        }
                        if (executor.getCode() != 0) {
                            processMessage(program);
                            throw new RunTimeErrorException(message.toString());
                        }
                    } // иначе ошибка на сервере
                } // иначе throws ProcessNotRunningException - невозможно, так как программа была запущена,
View Full Code Here

Examples of ProcessExecuting.ProcessExecutor

    public void compile(Program program) throws
            CompilationErrorException,
            CompilationInternalServerErrorException,
            CompilationTimeLimitExceededException {
        message = new StringBuffer();
        ProcessExecutor executor = new ProcessExecutor(
                program.getCompileCmd(),
                program.getDirPath(),
                TIME_LIMIT);
        BufferedReader reader = null;
        try {
            executor.execute(); // throws ProcessExecutingException
            reader = new BufferedReader(
                    new InputStreamReader(
                    getCompileInput(executor))); // throws ProcessExecutingException
            String line;
            while ((line = reader.readLine()) != null) { // throws IOException
                message.append(line + "\n");
            }
            int code = executor.waitForExit(); // throws ProcessExecutingException, InterruptedException
            System.err.println("Compilation process exited with code " + code);
            System.err.println("Compilation process was run for " + executor.getWorkTime());
            if (executor.isOutOfTime()) {
                throw new CompilationTimeLimitExceededException(
                        "Compilation process is out of time");
            }
            if (!program.canExecute()) {
                processMessage(program);
                throw new CompilationErrorException(message.toString());
            }
        } catch (IOException e) {
            try {
                int code = executor.waitForExit(); // throws ProcessExecutingException, InterruptedException
                System.err.println("Compilation process exited with code " + code);
                System.err.println("Compilation process was run for " + executor.getWorkTime());
            } catch (ProcessNotRunningException ex) {
                ex.printStackTrace();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

        else
            inputLines = new String[]{}; //to provoke stream closing
        //startCommand = startCommand + " " + instance.getID() + " " + INSTALL_ROOT;
        try {
            sLogger.log(Level.FINE, "general.exec_cmd", startCommand[0]);
      ProcessExecutor executor = new ProcessExecutor(startCommand, inputLines);
      executor.execute();
    }
                catch (ExecException ee) {
                    sLogger.log(Level.WARNING, "general.exec_cmd", ee);
                    throw new RuntimeException(Localizer.getValue(ExceptionType.SERVER_NO_START));
                }
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

      throw new IllegalArgumentException();
    }
    String stopCommand[] = instance.getStopCommand();
    try {
            sLogger.log(Level.FINE, "general.exec_cmd", stopCommand[0]);
      ProcessExecutor executor = new ProcessExecutor(stopCommand);
      executor.execute();
    }
    catch (Exception e) {
      throw new ConfigException(e.getMessage());
    }
  }
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

      throw new IllegalArgumentException();
    }
    String[] restartCommand = instance.getRestartCommand();
    try {
            sLogger.log(Level.FINE, "general.exec_cmd", restartCommand[0]);
      ProcessExecutor executor = new ProcessExecutor(restartCommand);
      executor.execute();
    }
    catch (Exception e) {
      throw new ConfigException(e.getMessage());
    }
  }
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

    }
    String[] command = instance.getGetSecurityTokensCommand();
        String[] inputLines = null;
        try {
            sLogger.log(Level.FINE, "general.gettokens_cmd", command[0]);
      ProcessExecutor executor = new ProcessExecutor(command);
      return executor.execute(true);
    }
                catch (ExecException ee) {
                        throw new RuntimeException(Localizer.getValue(ExceptionType.NO_RECEIVE_TOKENS));
                }
    catch (Exception e) {
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

              path2Auths = System.getProperty("PATH_2_AUTHS");
          if (System.getProperty("AUTH_TOKEN") != null)
              at = System.getProperty("AUTH_TOKEN");
          try {
              final String[] cmd = new String[]{path2Auths, user};
              ProcessExecutor pe = new ProcessExecutor(cmd);
              pe.setExecutionRetentionFlag(true);
              pe.execute();
              auths.append(pe.getLastExecutionOutput());
              final StringTokenizer st = new StringTokenizer(pe.getLastExecutionOutput(), at);
              while (st.hasMoreTokens()) {
                  String t = st.nextToken();
                  if (t != null)
                      t = t.trim();
                  if (AUTH1.equals(t) || AUTH2.equals(t) || AUTH3.equals(t)) {
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

   
    private boolean serviceNameExists(final String sn) {
        boolean exists = false;
        try {
            final String[] cmd = new String[] {"/usr/bin/svcs", sn};
            ProcessExecutor pe = new ProcessExecutor(cmd);
            pe.setExecutionRetentionFlag(true);
            pe.execute();
            exists = true;
        } catch(final Exception e) {
            //returns a non-zero status -- the service does not exist, status is already set
        }
        return ( exists );
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

        return ( tvset );
    }
   
    private void validateService(final SMFService smf) throws Exception {
        final String[] cmda = new String[]{SMFService.SVCCFG, "validate", smf.getManifestFilePath()};
        final ProcessExecutor pe = new ProcessExecutor(cmda);
        pe.execute();
        if (trace)
            printOut("Validated the SMF Service: " + smf.getFQSN() + " using: " + SMFService.SVCCFG);
    }
View Full Code Here

Examples of com.sun.enterprise.util.ProcessExecutor

        if (trace)
            printOut("Validated the SMF Service: " + smf.getFQSN() + " using: " + SMFService.SVCCFG);
    }
    private boolean importService(final SMFService smf) throws Exception {
        final String[] cmda = new String[]{SMFService.SVCCFG, "import", smf.getManifestFilePath()};
        final ProcessExecutor pe = new ProcessExecutor(cmda);
        pe.execute(); //throws ExecException in case of an error
        if (trace)
            printOut("Imported the SMF Service: " + smf.getFQSN());
        return ( true );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.