Exemplo n.º 1
0
  /**
   * Executes a file in a new process.
   *
   * @param commandLine The command line to execute. Must begins with the path to executable file.
   * @param workingDir The working directory for the new process to run.
   * @param logFile The file where standard output and standard error streams will be redirected.
   * @param timeoutInSeconds
   * @return The Process object of the running process.
   * @throws IOException
   * @throws InterruptedException
   */
  public TProcess executeInBackground(
      String[] commandLine, File workingDir, File logFile, double timeoutInSeconds) {
    logger.info("Running: " + commandLine + " workingDir=" + workingDir + " logFile=" + logFile);

    TProcess result = null;

    Runtime rt = Runtime.getRuntime();

    // Executing the command
    Process proc = null;
    try {
      proc = rt.exec(commandLine, null, workingDir);

      result = new TProcess(proc, timeoutInSeconds);
      if (logFile != null) {
        result.registerOutput(logFile, "");
      }

    } catch (IOException e) {
      e.printStackTrace();
      testCase.addTestResult(false, "An error occured during process execution");
    }

    return result;
  }
Exemplo n.º 2
0
  /**
   * Executes a file in a new process.
   *
   * @param commandLine The command line to execute. Must begins with the path to executable file.
   * @param workingDir The working directory for the new process to run.
   * @param logFile The file where standard output and standard error streams will be redirected.
   * @param timeoutInSeconds
   * @return Only when process is to the end.
   * @throws IOException
   * @throws InterruptedException
   */
  public int execute(String[] commandLine, File workingDir, File logFile, double timeoutInSeconds) {
    TProcess proc = executeInBackground(commandLine, workingDir, logFile, timeoutInSeconds);

    return proc.waitFor();
  }