예제 #1
0
  /**
   * Sets the list of environment variables when the process is created to be the provided name and
   * value pairs. <br>
   * <br>
   * <b>Note:</b> this will overwrite all previously saved environment variables.
   *
   * <p>Unless configured otherwise, these will be appended to the parent process' environment
   * variables.
   *
   * @param name_value_pairs An alternating list of names and associated values.
   * @return This instance of {@link ProcessBuilder}.
   */
  public ProcessBuilder withEnvironmentVariables(final Map<String, String> name_value_pairs) {
    if (name_value_pairs == null) {
      throw new IllegalArgumentException(
          "There must be a matching name and value (there should be an even number of provided arguments)");
    }

    this.env.clear();
    for (Map.Entry<String, String> e : name_value_pairs.entrySet()) {
      addEnvironmentVariable(e.getKey(), e.getValue());
    }
    return this;
  }
예제 #2
0
  /**
   * Sets the list of environment variables when the process is created to be the provided name and
   * value pairs. <br>
   * <br>
   * <b>Note:</b> this will overwrite all previously saved environment variables.
   *
   * <p>Unless configured otherwise, these will be appended to the parent process' environment
   * variables.
   *
   * @param name_value_pairs An alternating list of names and associated values.
   * @return This instance of {@link ProcessBuilder}.
   */
  public ProcessBuilder withEnvironmentVariables(final String... name_value_pairs) {
    if (name_value_pairs == null || (name_value_pairs.length % 2) != 0) {
      throw new IllegalArgumentException(
          "There must be a matching name and value (there should be an even number of provided arguments)");
    }

    this.env.clear();
    for (int i = 0; i < name_value_pairs.length; i += 2) {
      addEnvironmentVariable(name_value_pairs[i], name_value_pairs[i + 1]);
    }
    return this;
  }