Package ProcessExecuting

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


    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

TOP

Related Classes of ProcessExecuting.ProcessExecutor

Copyright © 2018 www.massapicom. 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.