final Proc procHolderForJoin = start(); LOGGER.log(Level.FINER, "Started the process {0}", procHolderForJoin);
Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).pwd(workDir).start();
envVars.put(e.getKey(),e.getValue()); r = join(launcher.launch().cmds(buildCommandLine(script)).envs(envVars).stdout(listener).pwd(ws).start());
@Override public Container launchSideContainer(TaskListener listener, String image, Container remotingContainer, List<Hint> hints) throws IOException, InterruptedException { ArgumentListBuilder args = new ArgumentListBuilder() .add("create") .add("--volumes-from", remotingContainer.getId()) .add("--net=container:" + remotingContainer.getId()) .add("--ipc=container:" + remotingContainer.getId()); applyHints(hints, args); args.add(image); ByteArrayOutputStream out = new ByteArrayOutputStream(); Launcher launcher = new Launcher.LocalLauncher(listener); int status = launchDockerCLI(launcher, args) .stdout(out).stderr(launcher.getListener().getLogger()).join(); final String containerId = out.toString(UTF_8).trim(); if (status != 0) { throw new IOException("Failed to run docker image"); } launchDockerCLI(launcher, new ArgumentListBuilder() .add("start", containerId)).start(); return new Container(image, containerId); }
private LaunchResult launch(@CheckForNull @Nonnull EnvVars launchEnv, boolean quiet, FilePath pwd, @Nonnull ArgumentListBuilder args) throws IOException, InterruptedException { // Prepend the docker command args.prepend(DockerTool.getExecutable(toolName, node, launcher.getListener(), launchEnv)); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Executing docker command {0}", args.toString()); } Launcher.ProcStarter procStarter = launcher.launch(); if (pwd != null) { procStarter.pwd(pwd); } LaunchResult result = new LaunchResult(); ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); result.setStatus(procStarter.quiet(quiet).cmds(args).envs(launchEnv).stdout(out).stderr(err).start().joinWithTimeout(CLIENT_TIMEOUT, TimeUnit.SECONDS, launcher.getListener())); final String charsetName = Charset.defaultCharset().name(); result.setOut(out.toString(charsetName)); result.setErr(err.toString(charsetName)); return result; }
@Override public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { Charset charset = Charset.defaultCharset(); FilePath basePath = new FilePath(f); Launcher launcher = basePath.createLauncher(new StreamTaskListener(new NullOutputStream(), charset)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Proc starter = launcher.launch().cmdAsSingleString("uname -m").stdout(baos).start(); int exitCode = starter.join(); if (exitCode != 0) { throw new IOException("Fail to execute 'uname -m' because: " + baos.toString(charset.name())); } return new String(baos.toByteArray(), charset).trim(); } };
static int joinWithPossibleTimeout(ProcStarter proc, boolean useTimeout, final TaskListener listener) throws IOException, InterruptedException { return useTimeout ? proc.start().joinWithTimeout(/* #4528: not in JDK 5: 1, TimeUnit.HOURS*/60 * 60, TimeUnit.SECONDS, listener) : proc.join(); }
public Proc getLaunchedProc(String[] cmdWithExec, String[] env, InputStream inputStream, OutputStream out, FilePath path) throws IOException { return getLauncher().launch().cmds(cmdWithExec).envs(env).stdin(inputStream).stdout(out).pwd(path).start(); }
private void runCommentsRemoverProcess(FilePath workspace, Launcher launcher, TaskListener listener, File removerScriptDir, File outputDirPath) throws IOException, InterruptedException { String pythonPath = getDescriptor().getPythonPath(); String pipPath = getDescriptor().getPipPath(); String pipExecutable = StringUtils.isEmpty(pythonPath) ? "pip" : pipPath; String[] pipCommand = new String[]{pipExecutable, "install", "-r", removerScriptDir + File.separator + "requirements.txt", "-q"}; listener.getLogger().println("Installing pip requirements [" + StringUtils.join(pipCommand, " ") + "]..."); runProcess(launcher.launch().cmds(pipCommand).readStdout().start(), listener); String pythonExecutable = StringUtils.isEmpty(pythonPath) ? "python" : pythonPath; String[] commentsRemoverCommand = new String[]{pythonExecutable, removerScriptDir + File.separator + COMMENTS_REMOVER_ENTRY_FILE, workspace.getRemote() + File.separator + filename, language, outputDirPath.getAbsolutePath()}; listener.getLogger().println("Executing script [" + StringUtils.join(commentsRemoverCommand, " ") + "]..."); runProcess(launcher.launch().cmds(commentsRemoverCommand).readStdout().start(), listener); }
private Proc startFitnesse(FilePath workingDirectory, Launcher launcher) throws IOException, InterruptedException { logger.println("Starting new Fitnesse instance..."); ProcStarter procStarter = launcher.launch().cmds(getJavaCmd(workingDirectory)); procStarter.pwd(getFilePath(workingDirectory, builder.getFitnesseJavaWorkingDirectory())); procStarter.stdout(logger).stderr(logger); return procStarter.start(); }
/** * Who is executing this {@link DockerClient} instance. * * @return a {@link String} containing the <strong>uid:gid</strong>. */ public String whoAmI() throws IOException, InterruptedException { ByteArrayOutputStream userId = new ByteArrayOutputStream(); launcher.launch().cmds("id", "-u").quiet(true).stdout(userId).start().joinWithTimeout(CLIENT_TIMEOUT, TimeUnit.SECONDS, launcher.getListener()); ByteArrayOutputStream groupId = new ByteArrayOutputStream(); launcher.launch().cmds("id", "-g").quiet(true).stdout(groupId).start().joinWithTimeout(CLIENT_TIMEOUT, TimeUnit.SECONDS, launcher.getListener()); final String charsetName = Charset.defaultCharset().name(); return String.format("%s:%s", userId.toString(charsetName).trim(), groupId.toString(charsetName).trim()); }
/** * Starts the process and waits for its completion. */ public int join() throws IOException, InterruptedException { return start().join(); }
public int runCmd(String[] commands, FilePath workspace, OutputStream logger, Launcher launcher, EnvVars envVars) throws InterruptedException, IOException { try { return launcher.launch().cmds(commands).envs(envVars).stdout(logger).stderr(logger).pwd(workspace).start().join(); } catch (IOException ex) { logger.write(ex.getMessage().getBytes()); if (printDebugOutput) { logger.write(Throwables.getStackTraceAsString(ex).getBytes()); } return 1; } }
/** * Starts the process and waits for its completion. */ public int join() throws IOException, InterruptedException { return start().join(); }
/** * Starts the process and waits for its completion. */ public int join() throws IOException, InterruptedException { return start().join(); }
public String runCommandForOutput(String command) throws DebianizingException { try { String actualCommand = MessageFormat.format("bash -c ''{0}''", command); return CharStreams.toString(new InputStreamReader(launcher.launch().cmdAsSingleString(actualCommand).readStdout().start().getStdout())); } catch (IOException e) { e.printStackTrace(listener.getLogger()); throw new DebianizingException(MessageFormat.format("Command <{0}> failed", command), e); } }
/** * For use with {@link #launch} (or similar) when running commands not inside a build and which therefore might not be easily killed. */ public static int joinWithPossibleTimeout(ProcStarter proc, boolean useTimeout, final TaskListener listener) throws IOException, InterruptedException { return useTimeout ? proc.start().joinWithTimeout(60 * 60, TimeUnit.SECONDS, listener) : proc.join(); }
public static void checkForSvnServe() throws InterruptedException { LocalLauncher launcher = new LocalLauncher(StreamTaskListener.fromStdout()); try { launcher.launch().cmds("svnserve","--help").start().join(); } catch (IOException e) { // TODO better to add a docker-fixtures test dep so CI builds can run these tests throw new AssumptionViolatedException("svnserve apparently not installed", e); } }
/** * Starts the process and waits for its completion. */ public int join() throws IOException, InterruptedException { return start().join(); }
if (reverseStderr) ps.readStderr(); final Proc p = ps.start();