List of usage examples for java.lang Process waitFor
public abstract int waitFor() throws InterruptedException;
From source file:org.auraframework.archetype.AuraArchetypeSimpleTestMANUAL.java
private void goldMavenOutput(Process process, String suffix, String description) throws Exception { int status = process.waitFor(); String output = IOUtil.readText(new InputStreamReader(process.getInputStream())); if (status != 0) { fail(description + " Process output:\n" + output); }/* ww w .jav a 2 s.com*/ int index = output.lastIndexOf(END_BUILD); if (index >= 0) { output = output.substring(0, index); } // ignore path refs output = output.replace(workspace.getAbsolutePath(), "TEMPDIR"); // ignore download progress updates output = output.replaceAll("\n(?:\\s*\\d+ .?B)+", ""); output = output.replaceAll("\\s*Downloading: [^\n]+", ""); output = output.replaceAll("\\s*Downloaded: [^\n]+", ""); output = output.replaceAll("\\s*Installing [^\n]+", ""); goldFileText(output, suffix); }
From source file:com.migratebird.script.runner.impl.Application.java
public ProcessOutput execute(boolean logCommand, String... arguments) { try {/* w w w. ja v a 2 s . c o m*/ List<String> commandWithArguments = getProcessArguments(arguments); ProcessBuilder processBuilder = createProcessBuilder(commandWithArguments); Process process = processBuilder.start(); OutputProcessor outputProcessor = new OutputProcessor(process); outputProcessor.start(); process.waitFor(); String output = outputProcessor.getOutput(); int exitValue = process.exitValue(); logOutput(commandWithArguments, output, logCommand); return new ProcessOutput(output, exitValue); } catch (Exception e) { throw new MigrateBirdException("Failed to execute command.", e); } }
From source file:net.solarnetwork.node.dao.jdbc.derby.DerbyOnlineSyncJob.java
private void performSync(String dbPath) { assert syncCommand != null; List<String> cmd = new ArrayList<String>(syncCommand.size()); for (String param : syncCommand) { param = param.replace(SOURCE_DIRECTORY_PLACEHOLDER, dbPath); param = param.replace(DESTINATION_DIRECTORY_PLACEHOLDER, destinationPath); cmd.add(param);/* ww w. jav a 2 s. co m*/ } if (log.isDebugEnabled()) { StringBuilder buf = new StringBuilder(); for (String p : cmd) { if (buf.length() > 0) { buf.append(' '); } buf.append(p); } log.debug("Derby sync command: {}", buf.toString()); } ProcessBuilder pb = new ProcessBuilder(cmd); BufferedReader in = null; PrintWriter out = null; try { Process pr = pb.start(); pr.waitFor(); if (pr.exitValue() == 0) { if (log.isDebugEnabled()) { in = new BufferedReader(new InputStreamReader(pr.getInputStream())); StringBuilder buf = new StringBuilder(); String line = null; while ((line = in.readLine()) != null) { buf.append(line).append('\n'); } log.debug("Derby sync command output:\n{}", buf.toString()); } log.info("Derby backup sync complete"); } else { StringBuilder buf = new StringBuilder(); in = new BufferedReader(new InputStreamReader(pr.getErrorStream())); String line = null; while ((line = in.readLine()) != null) { buf.append(line).append('\n'); } log.error("Sync command returned non-zero exit code {}: {}", pr.exitValue(), buf.toString().trim()); } } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore } } if (out != null) { out.flush(); out.close(); } } }
From source file:it.sardegnaricerche.voiceid.sr.Voiceid.java
/** * Convert to wav the inputFile to be processed by diarizator. * /* ww w.ja va 2 s .com*/ * @throws IOException */ private void toWav() throws IOException { logger.fine("Gstreamer initialized"); String filename = inputfile.getAbsolutePath(); String name = Utils.getBasename(inputfile); String line[] = { "/bin/sh", "-c", "gst-launch filesrc location='" + filename + "' ! decodebin ! audioresample ! 'audio/x-raw-int,rate=16000' ! audioconvert !" + " 'audio/x-raw-int,rate=16000,depth=16,signed=true,channels=1' ! wavenc ! filesink location=" + name + ".wav " }; // TODO: fix for other OS' vvvvvvvvvv // logger.info(System.getProperty("os.name").toLowerCase()); logger.fine(line[2]); try { Process p = Runtime.getRuntime().exec(line); p.waitFor(); logger.fine(p.exitValue() + ""); } catch (Exception err) { logger.severe(err.getMessage()); } // Pipeline pipe = Pipeline.launch(line[2]); // pipe.play(); // logger.info(pipe.getState().toString()); this.wavPath = new File(name + ".wav"); }
From source file:com.mbrlabs.mundus.assets.FbxConv.java
public FbxConvResult execute() { FbxConvResult result = new FbxConvResult(); if (input == null || output == null) { result.setSuccess(false);/*ww w . ja v a2 s.c o m*/ result.setResultCode(FbxConvResult.RESULT_CODE_PARAM_ERROR); Log.error(TAG, "FbxCov input or output not defined"); return result; } if (!input.endsWith("fbx")) { result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_WRONG_INPUT_FORMAT); Log.error(TAG, "FbxCov input format not supported"); } // build arguments String outputFilename = FilenameUtils.getBaseName(input); List<String> args = new ArrayList<String>(6); if (flipTexture) args.add("-f"); if (verbose) args.add("-v"); if (outputFormat == OUTPUT_FORMAT_G3DJ) { args.add("-o"); args.add("g3dj"); outputFilename += ".g3dj"; } else { outputFilename += ".g3db"; } args.add(input); String path = FilenameUtils.concat(output, outputFilename); args.add(path); Log.debug("FbxConv", "Command: " + args); pb.command().addAll(args); // execute fbx-conv process try { Process process = pb.start(); int exitCode = process.waitFor(); String log = IOUtils.toString(process.getInputStream()); if (exitCode == 0 && !log.contains("ERROR")) { result.setSuccess(true); result.setOutputFile(path); } result.setLog(log); } catch (IOException e) { e.printStackTrace(); result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_IO_ERROR); } catch (InterruptedException e) { e.printStackTrace(); result.setSuccess(false); result.setResultCode(FbxConvResult.RESULT_CODE_INTERRUPTED); } return result; }
From source file:net.sf.yal10n.svn.SVNUtilTest.java
/** * Verify that git checkout works./*from www . j av a 2 s .c o m*/ * @throws Exception any error */ @Test public void testGitCheckout() throws Exception { SVNUtil svnUtil = new SVNUtil(); Log log = new NullLog(); log = new SystemStreamLog(); String destination = new File("./target/gitrepos/repo1-checkout").getCanonicalPath(); if (new File(destination).exists()) { FileUtils.deleteDirectory(destination); } Process unzip = Runtime.getRuntime().exec("unzip -o repo1.zip", null, new File("./src/it/git-it/gitrepos/")); Assert.assertEquals(0, unzip.waitFor()); String url = "./src/it/git-it/gitrepos/repo1/.git"; String checkout = svnUtil.checkout(log, ScmType.GIT, url, destination); Assert.assertEquals("f5d50077a92f9e29d704518ab2fbd9ecf7307214", checkout); File dstPath = new File(destination); Assert.assertTrue(dstPath.exists() && dstPath.isDirectory()); String[] files = dstPath.list(); Arrays.sort(files); Assert.assertEquals("[.git, project-a]", Arrays.toString(files)); }
From source file:io.wcm.maven.plugins.nodejs.mojo.Task.java
private void startProcess(ProcessBuilder processBuilder) throws MojoExecutionException { try {/* w ww . ja va 2s. c o m*/ final Process process = processBuilder.start(); getLog().info("Running process: " + StringUtils.join(processBuilder.command(), " ")); initLogging(process); int result = process.waitFor(); if (result != 0) { throw new MojoExecutionException("Process: " + StringUtils.join(processBuilder.command(), " ") + " terminated with " + result); } } catch (IOException ex) { throw new MojoExecutionException( "Error executing process: " + StringUtils.join(processBuilder.command(), " "), ex); } catch (InterruptedException ex) { throw new MojoExecutionException( "Error executing process: " + StringUtils.join(processBuilder.command(), " "), ex); } }
From source file:dpfmanager.shell.modules.periodic.core.ControllerWindows.java
@Override public boolean deletePeriodicalCheck(String uuid) { try {//w ww .j a v a 2 s . c o m createIfNotExistsVBS(); String command = "schtasks /delete /f /tn \"" + uuid + "\""; Process proc = Runtime.getRuntime().exec(command); proc.waitFor(); return (proc.exitValue() == 0); } catch (Exception e) { return false; } }
From source file:net.duckling.ddl.util.FileUtil.java
/** * Runs a simple command in given directory. * The environment is inherited from the parent process (e.g. the * one in which this Java VM runs)./*w ww. j ava2 s .c o m*/ * * @return Standard output from the command. * @param command The command to run * @param directory The working directory to run the command in * @throws IOException If the command failed * @throws InterruptedException If the command was halted */ public static String runSimpleCommand(String command, String directory) throws IOException, InterruptedException { StringBuffer result = new StringBuffer(); LOG.info("Running simple command " + command + " in " + directory); Process process = Runtime.getRuntime().exec(command, null, new File(directory)); BufferedReader stdout = null; BufferedReader stderr = null; try { stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); stderr = new BufferedReader(new InputStreamReader(process.getErrorStream())); String line; while ((line = stdout.readLine()) != null) { result.append(line).append("\n"); } StringBuffer error = new StringBuffer(); while ((line = stderr.readLine()) != null) { error.append(line).append("\n"); } if (error.length() > 0) { LOG.error("Command failed, error stream is: " + error); } process.waitFor(); } finally { // we must close all by exec(..) opened streams: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4784692 process.getInputStream().close(); if (stdout != null) { stdout.close(); } if (stderr != null) { stderr.close(); } } return result.toString(); }
From source file:org.zenoss.app.metric.zapp.ManagedReporter.java
String exectHostname() throws InterruptedException { int exit;/* www.ja v a2 s . co m*/ String host = null; try { Process p = getProcBuilder().start(); exit = p.waitFor(); if (exit == 0) { host = new BufferedReader(new InputStreamReader(p.getInputStream())).readLine(); } else { String error = new BufferedReader(new InputStreamReader(p.getErrorStream())).readLine(); LOG.info("Could not get exec hostname -s: exit {} {}", exit, Strings.nullToEmpty(error)); } } catch (IOException e) { LOG.info("Error getting hostname {}", e.toString()); LOG.debug("IO error getting localhost", e); } return host; }