java.lang.ProcessBuilder.inheritIO()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(692)

本文整理了Java中java.lang.ProcessBuilder.inheritIO()方法的一些代码示例,展示了ProcessBuilder.inheritIO()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ProcessBuilder.inheritIO()方法的具体详情如下:
包路径:java.lang.ProcessBuilder
类名称:ProcessBuilder
方法名:inheritIO

ProcessBuilder.inheritIO介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

import java.io.IOException;

public class CLS {
  public static void main(String... arg) throws IOException, InterruptedException {
    new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
  }
}

代码示例来源:origin: apache/flink

public static AutoClosableProcess runNonBlocking(String step, String... commands) throws IOException {
  LOG.info("Step Started: " + step);
  Process process = new ProcessBuilder()
    .command(commands)
    .inheritIO()
    .start();
  return new AutoClosableProcess(process);
}

代码示例来源:origin: apache/hive

public static Process runCmdAsync(List<String> cmd) {
  try {
   LOG.info("Running command async: " + cmd);
   return new ProcessBuilder(cmd).inheritIO().start();
  } catch (IOException ex) {
   throw new IllegalStateException(ex);
  }
 }
}

代码示例来源:origin: stackoverflow.com

Process p = new ProcessBuilder().inheritIO().command("command1").start();

代码示例来源:origin: real-logic/aeron

private static void clearScreen() throws Exception
  {
    if (SystemUtil.osName().contains("win"))
    {
      new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
    }
    else
    {
      System.out.print(ANSI_CLS + ANSI_HOME);
    }
  }
}

代码示例来源:origin: apache/flink

public static void runBlocking(String step, Duration timeout, String... commands) throws IOException {
  LOG.info("Step started: " + step);
  Process process = new ProcessBuilder()
    .command(commands)
    .inheritIO()
    .start();
  try (AutoClosableProcess autoProcess = new AutoClosableProcess(process)) {
    final boolean success = process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS);
    if (!success) {
      throw new TimeoutException();
    }
  } catch (TimeoutException | InterruptedException e) {
    throw new RuntimeException(step + " failed due to timeout.");
  }
  LOG.info("Step complete: " + step);
}

代码示例来源:origin: aragozin/jvm-tools

public static void start(List<String> commands) {
    try {
      ProcessBuilder pb = new ProcessBuilder(commands);
      pb.inheritIO();
      System.exit(pb.start().waitFor());
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.exit(-1);
  }    
}

代码示例来源:origin: jphp-group/jphp

@Signature
public WrapProcess inheritIO() {
  if (processBuilder == null)
    throw new IllegalStateException("Process already started and it cannot set inheritIO().");
  processBuilder.inheritIO();
  return this;
}

代码示例来源:origin: sleekbyte/tailor

protected static void integrateTailor(String absolutePath) throws IOException, InterruptedException {
  File tempScript = createTempRubyScript(absolutePath);
  ProcessBuilder pb = new ProcessBuilder("ruby", tempScript.toString());
  pb.inheritIO().start().waitFor();
  if (!tempScript.delete()) {
    throw new FileNotFoundException("Failed to delete file " + tempScript);
  }
}

代码示例来源:origin: azkaban/azkaban

/**
 * API to execute a command on behalf of another user.
 *
 * @param user The proxy user
 * @param command the list containing the program and its arguments
 * @return The return value of the shell command
 */
public int execute(final String user, final List<String> command) throws IOException {
 log.info("Command: " + command);
 final Process process = new ProcessBuilder()
   .command(constructExecuteAsCommand(user, command))
   .inheritIO()
   .start();
 int exitCode;
 try {
  exitCode = process.waitFor();
 } catch (final InterruptedException e) {
  log.error(e.getMessage(), e);
  exitCode = 1;
 }
 return exitCode;
}

代码示例来源:origin: jmxtrans/jmxtrans

@Override
@IgnoreJRERequirement // ProcessBuilder.inheritIO() was introduced in Java 7. As this is only used in test, let's ignore it.
protected void before() throws Throwable {
  List<String> command = new ArrayList<String>(asList("java", "-cp", getCurrentClasspath()));
  for(Map.Entry<Object, Object> property: properties.entrySet()) {
    command.add("-D"+property.getKey()+"="+property.getValue());
  }
  command.add(appClass.getCanonicalName());
  if (appArgs != null) {
    command.addAll(asList(appArgs));
  }
  ProcessBuilder processBuilder = new ProcessBuilder().command(command)
    .inheritIO();
  if (outputFile != null) {
    processBuilder.redirectOutput(outputFile);
  }
  app = processBuilder.start();
}

代码示例来源:origin: bytedeco/javacpp

return pb.inheritIO().start().waitFor();

代码示例来源:origin: eclipse-vertx/vert.x

protected Process startExternalNode(int id) throws Exception {
 String javaHome = System.getProperty("java.home");
 String classpath = System.getProperty("java.class.path");
 List<String> command = new ArrayList<>();
 command.add(javaHome + File.separator + "bin" + File.separator + "java");
 command.add("-classpath");
 command.add(classpath);
 command.addAll(getExternalNodeSystemProperties());
 command.add(Launcher.class.getName());
 command.add("run");
 command.add(FaultToleranceVerticle.class.getName());
 command.add("-cluster");
 command.add("-conf");
 command.add(new JsonObject().put("id", id).put("addressesCount", ADDRESSES_COUNT).encode());
 return new ProcessBuilder(command).inheritIO().start();
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
  public void testThatAllThreadsAreDaemons() throws Exception {
    ProcessBuilder processBuilder = new ProcessBuilder(
      new File(System.getProperty("java.home")).toPath().resolve("bin").resolve("java").toString(),
      "-ea",
      "-classpath",
      System.getProperty("java.class.path"),
      DaemonTest.class.getCanonicalName()
    );

    assertEquals(0, processBuilder.inheritIO().start().waitFor());
  }
}

代码示例来源:origin: apache/incubator-gobblin

private void createInstallation()
  throws IOException {
 File srcDir = new File(BASE_ELASTICSEARCH_INSTALL);
 if (!srcDir.exists()) {
  throw new IOException("Could not find base elasticsearch instance installed at " + srcDir.getAbsolutePath() + "\n"
    + "Run ./gradlew :gobblin-modules:gobblin-elasticsearch:installTestDependencies before running this test");
 }
 File destDir = new File(_testInstallDirectory);
 log.debug("About to recreate directory : {}", destDir.getPath());
 if (destDir.exists()) {
  org.apache.commons.io.FileUtils.deleteDirectory(destDir);
 }
 String[] commands = {"cp", "-r", srcDir.getAbsolutePath(), destDir.getAbsolutePath()};
 try {
  log.debug("{}: Will run command: {}", this._pid, Arrays.toString(commands));
  Process copyProcess = new ProcessBuilder().inheritIO().command(commands).start();
  copyProcess.waitFor();
 } catch (Exception e) {
  log.error("Failed to create installation directory at {}", destDir.getPath(), e);
  Throwables.propagate(e);
 }
}

代码示例来源:origin: Netflix/Priam

Process process = processBuilder.inheritIO().start();
logger.info(
    "Started PostRestoreHook: {} - Attempt#{}",

代码示例来源:origin: ehcache/ehcache3

public static CompletableFuture<Integer> exec(Class<?> klass, String ... args) throws IOException, InterruptedException {
 String javaHome = System.getProperty("java.home");
 String javaBin = javaHome + separator + "bin" + separator + "java";
 String classpath = System.getProperty("java.class.path");
 String className = klass.getName();
 ProcessBuilder builder = new ProcessBuilder(
  javaBin, "-cp", classpath, className);
 builder.command().addAll(asList(args));
 Process process = builder.inheritIO().start();
 return CompletableFuture.supplyAsync(() -> {
  while (process.isAlive()) {
   try {
    process.waitFor();
   } catch (InterruptedException e) {
    // This should not happen but continue spinning if it does since the actual process is not done yet
   }
  }
  return process.exitValue();
 });
}

代码示例来源:origin: Netflix/genie

.inheritIO();

代码示例来源:origin: apache/incubator-gobblin

elasticProcess = new ProcessBuilder().inheritIO().command(commands).start();
if (elasticProcess != null) {

代码示例来源:origin: apache/incubator-gobblin

couchbaseProcess = new ProcessBuilder().inheritIO().command(commands).start();

相关文章