コード例 #1
0
ファイル: ProcessBuilder.java プロジェクト: jcommon/process
 /**
  * Creates a deep copy of this instance.
  *
  * @see Cloneable#clone()
  */
 public ProcessBuilder copy() {
   final ProcessBuilder builder = new ProcessBuilder();
   builder.inherit_parent_environment = inherit_parent_environment;
   builder.parent_environment = parent_environment;
   builder.executable = executable;
   builder.env = env.copy();
   builder.arguments.addAll(arguments);
   builder.listeners.addAll(listeners);
   return builder;
 }
コード例 #2
0
ファイル: ProcessResources.java プロジェクト: jcommon/process
public class ProcessResources {
  public static final int STANDARD_MESSAGE_COUNT = 10;

  private static final ProcessBuilder windows_builder_stdin_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDIN_1)
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_stderr_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDERR_1)
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_stdout_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDOUT_1)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_env_var_echo =
      ProcessBuilder.create()
          .withExecutable("cmd.exe")
          .andArgument("/c")
          .andArgument(Resources.ENV_VAR_ECHO)
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_stdout_echo_repeat =
      ProcessBuilder.create()
          .withExecutable("cmd.exe")
          .andArgument("/c")
          .andArgument(Resources.STDOUT_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_stderr_echo_repeat =
      ProcessBuilder.create()
          .withExecutable("cmd.exe")
          .andArgument("/c")
          .andArgument(Resources.STDERR_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_stdout_stderr_echo_repeat =
      ProcessBuilder.create()
          .withExecutable("cmd.exe")
          .andArgument("/c")
          .andArgument(Resources.STDOUT_STDERR_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder windows_builder_server =
      ProcessBuilder.create()
          .withExecutable("cmd.exe")
          .andArgument("/c")
          .andArgument("C:\\gitmo\\websphere-8.5.0\\bin\\server.bat")
          .andArgument("start")
          .andArgument("8280")
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder unix_builder_stdin_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDIN_1)
          .withListener(StandardStreamPipe.create());

  private static final ProcessBuilder unix_builder_stderr_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDERR_1)
          .withListener(StandardStreamPipe.create());

  private static final ProcessBuilder unix_builder_stdout_1 =
      ProcessBuilder.create()
          .withExecutable(Resources.STDOUT_1)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(StandardStreamPipe.create());

  private static final ProcessBuilder unix_builder_env_var_echo =
      ProcessBuilder.create()
          .withExecutable(Resources.ENV_VAR_ECHO)
          .withListener(
              StandardStreamPipe.create()
              // .redirectStdOut(StandardStream.Null)
              // .redirectStdErr(StandardStream.Null)
              );

  private static final ProcessBuilder unix_builder_stdout_echo_repeat =
      ProcessBuilder.create()
          .withExecutable(Resources.STDOUT_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(StandardStreamPipe.create());

  private static final ProcessBuilder unix_builder_stderr_echo_repeat =
      ProcessBuilder.create()
          .withExecutable(Resources.STDERR_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(StandardStreamPipe.create());

  private static final ProcessBuilder unix_builder_stdout_stderr_echo_repeat =
      ProcessBuilder.create()
          .withExecutable(Resources.STDOUT_STDERR_ECHO_REPEAT)
          .andArgument(Integer.toString(STANDARD_MESSAGE_COUNT))
          .withListener(StandardStreamPipe.create());

  public static final ProcessBuilder STDIN_1,
      STDERR_1,
      STDOUT_1,
      ENV_VAR_ECHO,
      STDERR_ECHO_REPEAT,
      STDOUT_ECHO_REPEAT,
      STDOUT_STDERR_ECHO_REPEAT;

  static {
    assertTrue(Resources.loadAllResources());

    switch (OSFamily.getSystemOSFamily()) {
      case Windows:
        STDIN_1 = windows_builder_stdin_1;
        STDERR_1 = windows_builder_stderr_1;
        STDOUT_1 = windows_builder_stdout_1;

        ENV_VAR_ECHO = windows_builder_env_var_echo;

        STDERR_ECHO_REPEAT = windows_builder_stderr_echo_repeat;
        STDOUT_ECHO_REPEAT = windows_builder_stdout_echo_repeat;
        STDOUT_STDERR_ECHO_REPEAT = windows_builder_stdout_stderr_echo_repeat;
        break;
      case Unix:
        STDIN_1 = unix_builder_stdin_1;
        STDERR_1 = unix_builder_stderr_1;
        STDOUT_1 = unix_builder_stdout_1;

        ENV_VAR_ECHO = unix_builder_env_var_echo;

        STDERR_ECHO_REPEAT = unix_builder_stderr_echo_repeat;
        STDOUT_ECHO_REPEAT = unix_builder_stdout_echo_repeat;
        STDOUT_STDERR_ECHO_REPEAT = unix_builder_stdout_stderr_echo_repeat;
        break;
      default:
        throw new UnsupportedOperationException(
            "This operating system (" + OSFamily.getSystemOSFamily() + ") is unsupported");
    }
  }
}