本文整理了Java中java.lang.ProcessBuilder.start()
方法的一些代码示例,展示了ProcessBuilder.start()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ProcessBuilder.start()
方法的具体详情如下:
包路径:java.lang.ProcessBuilder
类名称:ProcessBuilder
方法名:start
[英]Starts a new process based on the current state of this process builder.
[中]基于此process builder的当前状态启动新流程。
代码示例来源:origin: gocd/gocd
Process invoke(String[] command) throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder(command);
return processBuilder.start();
}
代码示例来源:origin: GoogleContainerTools/jib
/** Runs a {@code docker} command. */
private Process docker(String... subCommand) throws IOException {
return processBuilderFactory.apply(Arrays.asList(subCommand)).start();
}
}
代码示例来源: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: 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: alibaba/jstorm
protected static java.lang.Process launchProcess(final List<String> cmdlist,
final Map<String, String> environment) throws IOException {
ProcessBuilder builder = new ProcessBuilder(cmdlist);
builder.redirectErrorStream(true);
Map<String, String> process_evn = builder.environment();
for (Entry<String, String> entry : environment.entrySet()) {
process_evn.put(entry.getKey(), entry.getValue());
}
return builder.start();
}
代码示例来源:origin: alibaba/jstorm
protected static Process launchProcess(final List<String> cmdlist,
final Map<String, String> environment) throws IOException {
ProcessBuilder builder = new ProcessBuilder(cmdlist);
builder.redirectErrorStream(true);
Map<String, String> process_evn = builder.environment();
for (Entry<String, String> entry : environment.entrySet()) {
process_evn.put(entry.getKey(), entry.getValue());
}
return builder.start();
}
代码示例来源:origin: gocd/gocd
Process startProcess(ProcessBuilder processBuilder, String commandLineForDisplay) {
Process process;
try {
LOG.debug("[Command Line] START command {}", commandLineForDisplay);
process = processBuilder.start();
LOG.debug("[Command Line] END command {}", commandLineForDisplay);
} catch (IOException e) {
LOG.error("[Command Line] Failed executing [{}]", commandLineForDisplay);
LOG.error("[Command Line] Agent's Environment Variables: {}", System.getenv());
throw new CommandLineException(String.format("Error while executing [%s] \n Make sure this command can execute manually.", commandLineForDisplay), e);
}
return process;
}
代码示例来源: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: stanfordnlp/CoreNLP
public ProcessOutputStream(ProcessBuilder builder, Writer output, Writer error) throws IOException {
this.process = builder.start();
errWriterThread = new StreamGobbler(process.getErrorStream(), error);
outWriterThread = new StreamGobbler(process.getInputStream(), output);
errWriterThread.start();
outWriterThread.start();
}
代码示例来源: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: 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: prestodb/presto
protected void launchPrestoCli(List<String> arguments)
throws IOException
{
presto = new PrestoCliProcess(getProcessBuilder(arguments).start());
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!