return new LocalLauncher(out).launch().cmds(jenkinsExe, command).stdout(out).pwd(pwd).join(); } catch (IOException e) { if (e.getMessage().contains("CreateProcess") && e.getMessage().contains("=740")) {
@Override public void restart() throws IOException, InterruptedException { Jenkins jenkins = Jenkins.getInstanceOrNull(); try { if (jenkins != null) { jenkins.cleanUp(); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e); } File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); String exe = System.getenv("WINSW_EXECUTABLE"); File executable; if (exe!=null) executable = new File(exe); else executable = new File(home, "hudson.exe"); if (!executable.exists()) executable = new File(home, "jenkins.exe"); // use restart! to run hudson/jenkins.exe restart in a separate process, so it doesn't kill itself int r = new LocalLauncher(task).launch().cmds(executable, "restart!") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
Proc p = vmb.launch(new LocalLauncher(listener)).stdout(listener).pwd(workDir).start();
/** * Sends the stdout to the given {@link TaskListener}. */ public ProcStarter stdout(TaskListener out) { return stdout(out.getLogger()); }
@Override public void restart() throws IOException, InterruptedException { File me = getHudsonWar(); File home = me.getParentFile(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamTaskListener task = new StreamTaskListener(baos); task.getLogger().println("Restarting a service"); int r = new LocalLauncher(task).launch().cmds(new File(home, "hudson.exe"), "restart") .stdout(task).pwd(home).join(); if(r!=0) throw new IOException(baos.toString()); }
/** * Sends the stdout to the given {@link TaskListener}. */ public ProcStarter stdout(TaskListener out) { return stdout(out.getLogger()); }
/** * Primarily invoked from {@link ProcStarter#start()} to start a process * with a specific launcher. */ public abstract Proc launch(ProcStarter starter) throws IOException;
public void doListViews(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Hudson.getInstance().createLauncher(TaskListener.NULL).launch().cmds(getCleartoolExe(), "lsview", "-short").stdout(baos).join(); rsp.setContentType("text/plain"); rsp.getOutputStream().println("ClearCase Views found:\n"); baos.writeTo(rsp.getOutputStream()); }
/** * Copies a {@link ProcStarter}. */ @Nonnull public ProcStarter copy() { ProcStarter rhs = new ProcStarter().cmds(commands).pwd(pwd).masks(masks).stdin(stdin).stdout(stdout).stderr(stderr).envs(envs).quiet(quiet); rhs.reverseStdin = this.reverseStdin; rhs.reverseStderr = this.reverseStderr; rhs.reverseStdout = this.reverseStdout; return rhs; } }
/** * Sends the stdout to the given {@link TaskListener}. * * @param out Task listener * @return {@code this} */ public ProcStarter stdout(@Nonnull TaskListener out) { return stdout(out.getLogger()); }
@Test public void testLauncherFactoryIsSane() throws Exception { LauncherFactory factory = TestUtils.createLauncherFactory(j); assertEquals(factory.getStderr(), System.err); OutputStream out = new ByteArrayOutputStream(); factory.launch().stdout(out).cmdAsSingleString("echo hello").join(); assertEquals(out.toString(), "hello\n"); } }
int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join(); if (0 != r) { return false;
envVars.put(e.getKey(),e.getValue()); r = join(launcher.launch().cmds(buildCommandLine(script)).envs(envVars).stdout(listener).pwd(ws).start());
/** * Checks if "java" is in PATH on the given node. * * <p> * If it's not, then the user must specify a configured JDK, * so this is often useful for form field validation. */ public static boolean isDefaultJDKValid(Node n) { try { TaskListener listener = new StreamTaskListener(new NullStream()); Launcher launcher = n.createLauncher(listener); return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0; } catch (IOException e) { return false; } catch (InterruptedException e) { return false; } }
/** * @param env * Environment variable overrides. * @param in * null if there's no input. * @param workDir * null if the working directory could be anything. * @param out * stdout and stderr of the process will be sent to this stream. * the stream won't be closed. * * @deprecated as of 1.311 * Use {@link #launch()} and its associated builder pattern */ @Deprecated public Proc launch(String[] cmd, String[] env, InputStream in, OutputStream out, FilePath workDir) throws IOException { return launch(launch().cmds(cmd).envs(env).stdin(in).stdout(out).pwd(workDir)); }
@Override public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException { FilePath dir = preferredLocation(tool, node); // TODO support Unix scripts with interpreter line (see Shell.buildCommandLine) FilePath script = dir.createTextTempFile("hudson", getCommandFileExtension(), command); try { String cmd[] = getCommandCall(script); int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join(); if (r != 0) { throw new IOException("Command returned status " + r); } } finally { script.delete(); } return dir.child(getToolHome()); }
private static int system(File pwd, TaskListener listener, String... args) throws IOException, InterruptedException { return new LocalLauncher(listener).launch().cmds(args).stdout(System.out).pwd(pwd).join(); }
/** * Primarily invoked from {@link ProcStarter#start()} to start a process with a specific launcher. */ public abstract Proc launch(@Nonnull ProcStarter starter) throws IOException;
/** * Copies a {@link ProcStarter}. */ @Nonnull public ProcStarter copy() { ProcStarter rhs = new ProcStarter().cmds(commands).pwd(pwd).masks(masks).stdin(stdin).stdout(stdout).stderr(stderr).envs(envs).quiet(quiet); rhs.stdoutListener = stdoutListener; rhs.reverseStdin = this.reverseStdin; rhs.reverseStderr = this.reverseStderr; rhs.reverseStdout = this.reverseStdout; return rhs; } }