List of usage examples for java.lang ProcessBuilder inheritIO
public ProcessBuilder inheritIO()
From source file:edu.illinois.cs.cogcomp.CleanMojo.java
public void execute() throws MojoExecutionException { dFlag = FileUtils.getPlatformIndependentFilePath(dFlag); gspFlag = FileUtils.getPlatformIndependentFilePath(gspFlag); sourcepathFlag = FileUtils.getPlatformIndependentFilePath(sourcepathFlag); classpath.add(dFlag);// w ww .j a va 2 s . c om classpath.add(gspFlag); String newpath = StringUtils.join(classpath, File.pathSeparator); // We need to reverse the order we do the cleaning since there might be dependencies across // files List<String> fileList = Arrays.asList(lbjavaInputFileList); Collections.reverse(fileList); for (String lbjInputFile : fileList) { if (StringUtils.isEmpty(lbjInputFile)) { // making the optional-compile-step parameter happy. continue; } getLog().info("Calling Java edu.illinois.cs.cogcomp.lbjava.Main with the -x flag (for cleaning)..."); lbjInputFile = FileUtils.getPlatformIndependentFilePath(lbjInputFile); try { // The -x flag makes all the difference. String[] args = new String[] { "java", "-cp", newpath, "edu.illinois.cs.cogcomp.lbjava.Main", "-x", "-d", dFlag, "-gsp", gspFlag, "-sourcepath", sourcepathFlag, lbjInputFile }; ProcessBuilder pr = new ProcessBuilder(args); pr.inheritIO(); Process p = pr.start(); p.waitFor(); } catch (Exception e) { e.printStackTrace(); System.out.println("Yeah, an error."); } } }
From source file:com.netscape.cmstools.profile.ProfileEditCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/* www .j ava 2s. co m*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length < 1) { throw new Exception("No Profile ID specified."); } String profileId = cmdArgs[0]; ProfileClient profileClient = profileCLI.getProfileClient(); // read profile into temporary file byte[] orig = profileClient.retrieveProfileRaw(profileId); ProfileCLI.checkConfiguration(orig, false /* requireProfileId */, true /* requireDisabled */); Path tempFile = Files.createTempFile("pki", ".cfg"); try { Files.write(tempFile, orig); // invoke editor on temporary file String editor = System.getenv("EDITOR"); String[] command; if (editor == null || editor.trim().isEmpty()) { command = new String[] { "/usr/bin/env", "vi", tempFile.toString() }; } else { command = new String[] { editor.trim(), tempFile.toString() }; } ProcessBuilder pb = new ProcessBuilder(command); pb.inheritIO(); int exitCode = pb.start().waitFor(); if (exitCode != 0) { throw new Exception("Exited abnormally."); } // read data from temporary file and modify if changed byte[] cur = ProfileCLI.readRawProfileFromFile(tempFile); if (!Arrays.equals(cur, orig)) { profileClient.modifyProfileRaw(profileId, cur); } System.out.write(cur); } finally { Files.delete(tempFile); } }
From source file:com.netscape.cmstools.cli.HelpCLI.java
public void execute(String[] args) throws Exception { CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); String manPage = null;// www.j av a 2 s.c o m if (cmdArgs.length == 0) { // no command specified, show the pki man page manPage = parent.getManPage(); } else { // find all modules handling the specified command List<CLI> modules = parent.findModules(cmdArgs[0]); // find the module that has a man page starting from the last one for (int i = modules.size() - 1; i >= 0; i--) { CLI module = modules.get(i); manPage = module.getManPage(); if (manPage != null) break; } // if no module has a man page, show the pki man page if (manPage == null) manPage = parent.getManPage(); } while (true) { // display man page for the command ProcessBuilder pb = new ProcessBuilder("/usr/bin/man", manPage); pb.inheritIO(); Process p = pb.start(); int rc = p.waitFor(); if (rc == 16) { // man page not found, find the parent command int i = manPage.lastIndexOf('-'); if (i >= 0) { // parent command exists, try again manPage = manPage.substring(0, i); continue; } else { // parent command not found, stop break; } } else { // man page found or there's a different error, stop break; } } }
From source file:org.codehaus.mojo.exec.ExtendedExecutor.java
@Override protected Process launch(CommandLine command, Map<String, String> env, File dir) throws IOException { if (dir != null && !dir.exists()) { throw new IOException(dir + " doesn't exist."); }/*from w w w.ja v a 2 s.com*/ ProcessBuilder pb = new ProcessBuilder(command.toStrings()); pb.environment().putAll(env); pb.directory(dir); if (inheritIo) { pb.inheritIO(); } return pb.start(); }
From source file:com.sonar.it.android.AndroidTest.java
@Test @Ignore("Deactivated awaiting resolution of http://jira.sonarsource.com/browse/JC-145") public void should_run_lint_after_export_and_import_results() throws Exception { assumeTrue(AndroidTestSuite.isAtLeastPlugin1_1()); String response = exportProfile("it-profile"); File baseDir = new File("projects/SonarAndroidSample/app"); FileUtils.write(new File(baseDir, "lint.xml"), response, Charsets.UTF_8); ProcessBuilder pb = new ProcessBuilder("CMD", "/C", "gradle lint"); pb.directory(baseDir);// ww w .j a v a 2 s . co m pb.inheritIO(); Process gradleProcess = pb.start(); int exitStatus = gradleProcess.waitFor(); if (exitStatus != 0) { fail("Failed to execute gradle lint."); } SonarRunner analysis = SonarRunner.create().setProfile("it-profile").setProjectName("SonarAndroidSample2") .setProjectKey("SonarAndroidSample2").setProjectVersion("1.0").setSourceDirs("src/main") .setProjectDir(baseDir).setProperty("sonar.android.lint.report", "lint-report-build.xml") .setProperty("sonar.import_unknown_files", "true"); orchestrator.executeBuild(analysis); Resource project = sonar.find(ResourceQuery.createForMetrics("SonarAndroidSample2", "violations")); assertThat(project.getMeasureIntValue("violations")).isEqualTo(2); }
From source file:org.apache.metron.rest.service.impl.StormCLIWrapper.java
protected int runCommand(String[] command) throws RestException { ProcessBuilder pb = getProcessBuilder(command); pb.inheritIO(); LOG.debug("Running command: cmd={}", String.join(" ", command)); Process process;// w w w . j a v a 2 s .com try { process = pb.start(); process.waitFor(); } catch (Exception e) { throw new RestException(e); } int exitValue = process.exitValue(); LOG.debug("Command completed: cmd={}, exit={}", String.join(" ", command), exitValue); return exitValue; }
From source file:com.qhrtech.emr.launcher.TemplateLauncherManager.java
public void startUp() throws Exception { Process p = null;//from w ww . j a v a2s . c om synchronized (eventLock) { doGeneration(); if (launchCommand != null) { ProcessBuilder pb = new ProcessBuilder(launchCommand); p = pb.inheritIO().start(); } commandStarted = true; eventLock.notifyAll(); } if (p != null) { System.exit(p.waitFor()); } }
From source file:org.kie.workbench.common.services.backend.compiler.offprocess.impl.CompilerIPCCoordinatorImpl.java
private void invokeServerBuild(String mavenRepo, String projectPath, String uuid, String classpath, String alternateSettingsAbsPath, String queueName) throws Exception { String[] commandArrayServer = { javaBin, "-cp", getClasspathIncludedCurrentModuleDep(mavenRepo, classpath), "-Dorg.uberfire.nio.git.daemon.enabled=false", "-Dorg.uberfire.nio.ssh.daemon.enabled=false", ServerIPCImpl.class.getCanonicalName(), uuid, projectPath, mavenRepo, alternateSettingsAbsPath, queueName };// ww w .j a va 2 s.c o m if (logger.isDebugEnabled()) { logger.debug( "************************** \n Invoking server in a separate process with args: \n{} \n{} \n{} \n{} \n{} \n{} \n{} \n{} \n**************************", commandArrayServer); } ProcessBuilder serverPb = new ProcessBuilder(commandArrayServer); serverPb.directory(new File(projectPath)); serverPb.redirectErrorStream(true); serverPb.inheritIO(); writeStdOut(serverPb); }
From source file:abs.backend.erlang.ErlangTestDriver.java
/** * Complies code in workDir/* w w w .j a v a2s . co m*/ */ private void make(File workDir) throws Exception { ProcessBuilder pb = new ProcessBuilder("erl", "-pa", "ebin", "-noshell", "-noinput", "-eval", "case make:all() of up_to_date -> halt(0); _ -> halt(1) end."); pb.directory(workDir); pb.inheritIO(); Process p = pb.start(); Assert.assertEquals("Compile failed", 0, p.waitFor()); }
From source file:org.apache.htrace.util.HTracedProcess.java
public HTracedProcess(final File binPath, final File dataDir, final String host) throws IOException { // Create a notifier socket bound to a random port. ServerSocket listener = new ServerSocket(0); boolean success = false; Process process = null;//w w w.j a v a2s . c o m try { // Use a random port for the web address. No 'scheme' yet. String webAddress = host + ":0"; String logPath = new File(dataDir, "log.txt").getAbsolutePath(); // Pass cmdline args to htraced to it uses our test dir for data. ProcessBuilder pb = new ProcessBuilder(binPath.toString(), "-Dlog.level=TRACE", "-Dlog.path=" + logPath, "-Dweb.address=" + webAddress, "-Ddata.store.clear=true", "-Dstartup.notification.address=localhost:" + listener.getLocalPort(), "-Ddata.store.directories=" + dataDir.toString()); pb.redirectErrorStream(true); // Inherit STDERR/STDOUT i/o; dumps on console for now. Can add logs later. pb.inheritIO(); pb.directory(dataDir); //assert pb.redirectInput() == Redirect.PIPE; //assert pb.redirectOutput().file() == dataDir; process = pb.start(); assert process.getInputStream().read() == -1; StartupNotificationData data = readStartupNotification(listener); httpAddr = data.httpAddr; LOG.info("Started htraced process " + data.processId + " with http " + "address " + data.httpAddr + ", logging to " + logPath); success = true; } finally { if (!success) { // Clean up after failure if (process != null) { process.destroy(); process = null; } } delegate = process; listener.close(); } }