public CommandReturn runWithOutput() throws IOException {
    Process process = null;
    BufferedReader inReader = null;
    try {
      process = new ProcessBuilder(mCommand).redirectErrorStream(true).start();
      inReader =
              new BufferedReader(new InputStreamReader(process.getInputStream()));

      // read the output of the command
      StringBuilder stdout = new StringBuilder();
      String outLine = inReader.readLine();
      while (outLine != null) {
        stdout.append(outLine);
        stdout.append("\n");
        outLine = inReader.readLine();
      }

      // wait for the process to finish and check the exit code
      int exitCode = process.waitFor();
      if (exitCode != 0) {
        // log error instead of throwing exception
        LOG.warn(String.format("Non-zero exit code (%d) from command %s",
                exitCode, Arrays.toString(mCommand)));
      }

      CommandReturn cr = new CommandReturn(exitCode, mCommand, stdout.toString());

      // destroy the process
      if (process != null) {
        process.destroy();
      }

      return cr;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new IOException(e);
    } catch (Exception e) {
      return new CommandReturn(1, String.format("Command %s failed, exception is %s",
              Arrays.toString(mCommand), e.getMessage()));
    } finally {
      if (inReader != null) {
        inReader.close();
      }
      if (process != null) {
        process.destroy();
      }
    }
  }
@Test
  public void execCommandTolerateFailureSucceed() throws Exception {
    // create temp file
    File testDir = AlluxioTestDirectory.createTemporaryDirectory("command");

    File testFile = createFileInDir(testDir, "testFile");

    // ls temp file
    String[] testCommandSucceed = new String[]{"ls",
            String.format("%s", testDir.getAbsolutePath())};
    CommandReturn crs = new ShellCommand(testCommandSucceed).runWithOutput();
    assertEquals(0, crs.getExitCode());
    assertTrue(crs.getOutput().contains(testFile.getName()));
  }