示例#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;
  }
示例#2
0
  /**
   * Performs one call to executeLinuxCommandLine then checks the exit code. Automatically attaches
   * the log file to the test result.
   *
   * @param commandLine The command line arguments (usually separated with space " ").
   * @param workingDir The directory from where the command is launched.
   * @param logFile The file where standard and error output will be redirected.
   * @param timeoutInSeconds
   * @param expectedExitCode The expected value for exit code
   */
  public void checkExecuteLinuxCommandLine(
      String[] commandLine,
      File workingDir,
      File logFile,
      double timeoutInSeconds,
      int expectedExitCode) {
    int exitCode = -1;

    exitCode = executeLinuxCommandLine(commandLine, workingDir, logFile, timeoutInSeconds);

    if (logFile != null) {
      testCase.attachFile(logFile);
    } else {
      testCase.addError("Cannot attach file with null reference");
    }
    new TestToolNumbers(testCase).checkEquality(expectedExitCode, exitCode);
  }