<commit_before>// Copyright 2011 The MOE Authors All Rights Reserved.

package com.google.devtools.moe.client;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import dagger.Provides;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 *
 * @author <EMAIL> (<NAME>)
 */
@Singleton
public class SystemCommandRunner implements CommandRunner {
  private final Ui ui;

  @Inject
  public SystemCommandRunner(Ui ui) {
    this.ui = ui;
  }

  @Override
  public CommandOutput runCommandWithFullOutput(
      String cmd, List<String> args, String workingDirectory) throws CommandException {
    ImmutableList<String> cmdArgs =
        new ImmutableList.Builder<String>().add(cmd).addAll(args).build();

    ui.debug(workingDirectory + "$ " + Joiner.on(" ").join(cmdArgs));

    ProcessBuilder pb = new ProcessBuilder(cmdArgs);
    if (workingDirectory != null && !workingDirectory.isEmpty()) {
      pb.directory(new File(workingDirectory));
    }
    Process p;
    int returnStatus;
    String stdoutData, stderrData;
    try {
      p = pb.start();
      p.getOutputStream().close();
      // We need to read data from the output steams.
      // Why? Because if we don't read from them, then the process we have started will fill the
      // buffers and block. We will be in a deadlock.
      // If there were only one stream, we could just do repeated calls to read() until we got
      // EOF.
      // But because there are two streams (both stdout and stderr), we have to read from each.
      // read() is blocking, so we use available().

      Sink stdoutSink = new Sink(p.getInputStream());
      Sink stderrSink = new Sink(p.getErrorStream());
<commit_msg>Fix a case where we were passing user input into a string formatter. 	Change on 2015/07/27 by cgruber <<EMAIL>> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=99239870<commit_after>// Copyright 2011 The MOE Authors All Rights Reserved.

package com.google.devtools.moe.client;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import dagger.Provides;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 *
 * @author <EMAIL> (<NAME>)
 */
@Singleton
public class SystemCommandRunner implements CommandRunner {
  private final Ui ui;

  @Inject
  public SystemCommandRunner(Ui ui) {
    this.ui = ui;
  }

  @Override
  public CommandOutput runCommandWithFullOutput(
      String cmd, List<String> args, String workingDirectory) throws CommandException {
    ImmutableList<String> cmdArgs =
        new ImmutableList.Builder<String>().add(cmd).addAll(args).build();

    ui.debug("%s $ %s", workingDirectory, Joiner.on(" ").join(cmdArgs));

    ProcessBuilder pb = new ProcessBuilder(cmdArgs);
    if (workingDirectory != null && !workingDirectory.isEmpty()) {
      pb.directory(new File(workingDirectory));
    }
    Process p;
    int returnStatus;
    String stdoutData, stderrData;
    try {
      p = pb.start();
      p.getOutputStream().close();
      // We need to read data from the output steams.
      // Why? Because if we don't read from them, then the process we have started will fill the
      // buffers and block. We will be in a deadlock.
      // If there were only one stream, we could just do repeated calls to read() until we got
      // EOF.
      // But because there are two streams (both stdout and stderr), we have to read from each.
      // read() is blocking, so we use available().

      Sink stdoutSink = new Sink(p.getInputStream());
      Sink stderrSink = new Sink(p.getErrorStream());

{'fraction_non_alphanumeric': 0.11102583781018163, 'fraction_numerical': 0.0061396776669224865, 'mean_word_length': 3.354120267260579, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '935337', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1143, 'n_words': 373}