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

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

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

ProcessBuilder.<init>介绍

[英]Constructs a new ProcessBuilder instance with the specified operating system program and its arguments. Note that the list passed to this constructor is not copied, so any subsequent updates to it are reflected in this instance's state.
[中]使用指定的操作系统程序及其参数构造新的ProcessBuilder实例。请注意,传递给此构造函数的列表不会被复制,因此对它的任何后续更新都会反映在该实例的状态中。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

public ProcessOutputStream(String[] cmd, Writer writer) throws IOException {
 this(new ProcessBuilder(cmd), writer, writer);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public ProcessOutputStream(String[] cmd, Writer output, Writer error) throws IOException {
 this(new ProcessBuilder(cmd), output, error);
}

代码示例来源:origin: jenkinsci/jenkins

private int exec(String cmd) throws InterruptedException, IOException {
  ProcessBuilder pb = new ProcessBuilder(exe, cmd);
  pb.redirectErrorStream(true);
  Process p = pb.start();
  p.getOutputStream().close();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  copy(p.getInputStream(), baos);
  int r = p.waitFor();
  if (r!=0)
    LOGGER.info(exe+" cmd: output:\n"+baos);
  return r;
}

代码示例来源:origin: prestodb/presto

protected ProcessBuilder getProcessBuilder(List<String> arguments)
  {
    return new ProcessBuilder(ImmutableList.<String>builder()
        .add(JAVA_BIN, "-cp", CLASSPATH, Presto.class.getCanonicalName())
        .addAll(arguments)
        .build());
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public ProcessOutputStream(String[] cmd) throws IOException {
 this(new ProcessBuilder(cmd), new PrintWriter(System.out), new PrintWriter(System.err));
}

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

ProcessBuilder builder = new ProcessBuilder("/bin/bash");
builder.redirectErrorStream(true);
Process process = builder.start();

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

ProcessBuilder pb = new ProcessBuilder("myshellScript.sh", "myArg1", "myArg2");
Map<String, String> env = pb.environment();
env.put("VAR1", "myValue");
env.remove("OTHERVAR");
env.put("VAR2", env.get("VAR1") + "suffix");
pb.directory(new File("myDir"));
Process p = pb.start();

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

public synchronized int getUserHZ() throws IOException {
  if (userHz < 0) {
    ProcessBuilder pb = new ProcessBuilder("getconf", "CLK_TCK");
    Process p = pb.start();
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = in.readLine().trim();
    userHz = Integer.valueOf(line);
  }
  return userHz;
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static void runConllEval(String conllMentionEvalScript,
  String goldFile, String predictFile, String evalFile, String errFile) throws IOException {
 ProcessBuilder process = new ProcessBuilder(conllMentionEvalScript, "all", goldFile, predictFile);
 PrintWriter out = new PrintWriter(new FileOutputStream(evalFile));
 PrintWriter err = new PrintWriter(new FileOutputStream(errFile));
 SystemUtils.run(process, out, err);
 out.close();
 err.close();
}

代码示例来源: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: jenkinsci/jenkins

public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String,String> envVars) throws IOException {
  printCommandLine(cmd, workDir);
  ProcessBuilder pb = new ProcessBuilder(cmd);
  pb.directory(toFile(workDir));
  if (envVars!=null) pb.environment().putAll(envVars);
  return launchChannel(out, pb);
}

代码示例来源: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: prestodb/presto

public static Pager create(List<String> command)
{
  try {
    Process process = new ProcessBuilder()
        .command(command)
        .redirectOutput(ProcessBuilder.Redirect.INHERIT)
        .redirectError(ProcessBuilder.Redirect.INHERIT)
        .start();
    return new Pager(process.getOutputStream(), process);
  }
  catch (IOException e) {
    System.err.println("ERROR: failed to open pager: " + e.getMessage());
    return createNullPager();
  }
}

代码示例来源:origin: jenkinsci/jenkins

protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
    args.prepend(sudoExe(),"-S");
    listener.getLogger().println("$ "+Util.join(args.toList()," "));
    ProcessBuilder pb = new ProcessBuilder(args.toCommandArray());
    Process p = pb.start();
    // TODO: use -p to detect prompt
    // TODO: detect if the password didn't work
    PrintStream ps = new PrintStream(p.getOutputStream());
    ps.println(rootPassword);
    ps.println(rootPassword);
    ps.println(rootPassword);
    return p;
  }
}.start(listener,rootPassword);

代码示例来源:origin: Alluxio/alluxio

private static void stopAlluxio() throws Exception {
 String stopScript = PathUtils.concatPath(sConf.get(PropertyKey.HOME),
   "bin", "alluxio-stop.sh");
 ProcessBuilder pb = new ProcessBuilder(stopScript, "all");
 pb.start().waitFor();
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * @param err
 *      null to redirect stderr to stdout.
 */
public LocalProc(String[] cmd,String[] env,InputStream in,OutputStream out,OutputStream err,File workDir) throws IOException {
  this( calcName(cmd),
     stderr(environment(new ProcessBuilder(cmd),env).directory(workDir), err==null || err== SELFPUMP_OUTPUT),
     in, out, err );
}

代码示例来源:origin: jenkinsci/jenkins

protected Process sudoWithPass(ArgumentListBuilder args) throws IOException {
    listener.getLogger().println("Running with embedded_su");
    ProcessBuilder pb = new ProcessBuilder(args.prepend(sudoExe()).toCommandArray());
    return EmbeddedSu.startWithSu(rootUsername, rootPassword, pb);
  }
// in solaris, pfexec never asks for a password, so username==null means

代码示例来源:origin: Alluxio/alluxio

private static void stopAlluxioFramework() throws Exception {
 String stopScript = PathUtils.concatPath(sConf.get(PropertyKey.HOME),
   "integration", "mesos", "bin", "alluxio-mesos-stop.sh");
 ProcessBuilder pb = new ProcessBuilder(stopScript);
 pb.start().waitFor();
 // Wait for Mesos to unregister and shut down the Alluxio Framework.
 CommonUtils.sleepMs(5000);
}

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

private static void kill( int signal, Process process ) throws Exception
{
  int exitCode = new ProcessBuilder( "kill", "-" + signal, pidOf( process ) ).start().waitFor();
  if ( exitCode != 0 )
  {
    throw new IllegalStateException( "<kill -" + signal + "> failed, exit code: " + exitCode );
  }
}

代码示例来源: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();
}

相关文章