List of usage examples for java.lang Process getErrorStream
public abstract InputStream getErrorStream();
From source file:jcuda.utils.KernelLauncher.java
/** * The extension of the given file name is replaced with "ptx". * If the file with the resulting name does not exist or is older * than the source file, it is compiled from the given file * using NVCC. If the forceRebuild flag is 'true', then the PTX * file is rebuilt even if it already exists or is newer than the * source file. The name of the PTX file is returned. * * @param cuFileName The name of the .CU file * @param forceRebuild Whether the PTX file should be re-created * even if it exists already.//from ww w . j a va 2 s . c o m * @param nvccArguments Optional arguments for the NVCC * @return The name of the PTX file * @throws IOException If an I/O error occurs * @throws CudaException If the creation of the PTX file fails */ private static String preparePtxFile(String cuFileName, boolean forceRebuild, String... nvccArguments) throws IOException { logger.info("Preparing PTX for \n" + cuFileName); File cuFile = new File(cuFileName); if (!cuFile.exists()) throw new CudaException("Input file not found: " + cuFileName); // Replace the file extension with "ptx" String ptxFileName = null; int lastIndex = cuFileName.lastIndexOf('.'); if (lastIndex == -1) ptxFileName = cuFileName + ".ptx"; else ptxFileName = cuFileName.substring(0, lastIndex) + ".ptx"; // Return if the file already exists and should not be rebuilt File ptxFile = new File(ptxFileName); if (ptxFile.exists() && !forceRebuild) { long cuLastModified = cuFile.lastModified(); long ptxLastModified = ptxFile.lastModified(); if (cuLastModified < ptxLastModified) return ptxFileName; } // Build the command line String modelString = "-m" + System.getProperty("sun.arch.data.model"); String defaultArguments = ""; String optionalArguments = createArgumentsString(nvccArguments); String command = compilerPath + "nvcc " + modelString + " " + defaultArguments + " " + optionalArguments + " -ptx " + cuFile.getPath() + " -o " + ptxFileName; // Execute the command line and wait for the output logger.info("Executing\n" + command); Process process = Runtime.getRuntime().exec(command); String errorMessage = new String(toByteArray(process.getErrorStream())); String outputMessage = new String(toByteArray(process.getInputStream())); int exitValue = 0; try { exitValue = process.waitFor(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CudaException("Interrupted while waiting for nvcc output", e); } logger.info("nvcc process exitValue " + exitValue); if (exitValue != 0) { logger.error("errorMessage:\n" + errorMessage); logger.error("outputMessage:\n" + outputMessage); throw new CudaException("Could not create .ptx file: " + errorMessage); } return ptxFileName; }
From source file:com.antonjohansson.svncommit.core.utils.Bash.java
/** {@inheritDoc} */ @Override/* w w w . j av a 2 s .c o m*/ public void executeAndPipeOutput(Consumer<String> onData, Consumer<String> onError, Consumer<Boolean> onComplete, String... commandLines) { File scriptFile = getTemporaryScriptFile(asList(commandLines)); Process process = execute(path, scriptFile); try (InputStream logStream = process.getInputStream(); InputStream errorStream = process.getErrorStream()) { while (isAvailable(process, logStream, errorStream)) { if (logStream.available() > 0) { accept(onData, logStream); } if (errorStream.available() > 0) { accept(onError, errorStream); } } int exitValue = process.exitValue(); onComplete.accept(exitValue == 0); } catch (IOException e) { throw new RuntimeException("Could not execute temporary bash script", e); } }
From source file:ru.anr.cmdline.utils.SimpleOsCommand.java
/** * Execute specified command// ww w .ja va 2s .c om * * @param command * An os command * @return Command result (stdout or stderr) * @throws IOException * When error with result processing occures */ public String execute(String command) throws IOException { StringBuilder sb = new StringBuilder(); final File root = new File("."); // Starting from a current directory try { final Process p = Runtime.getRuntime().exec(command, null, root); Reader input = new InputStreamReader(p.getInputStream()); Reader errors = new InputStreamReader(p.getErrorStream()); for (String s : IOUtils.readLines(input)) { // stdout sb.append(s); sb.append(OsUtils.LINE_SEPARATOR); } for (String s : IOUtils.readLines(errors)) { // stderr sb.append(s); sb.append(OsUtils.LINE_SEPARATOR); } p.getOutputStream().close(); if (p.waitFor() != 0) { logger.error("The command '{}' did not complete successfully", command); } } catch (final InterruptedException e) { throw new IllegalStateException(e); } return sb.toString(); }
From source file:org.openmeetings.app.documents.GenerateThumbs.java
public HashMap<String, String> processImageWindows(String[] args) { HashMap<String, String> returnMap = new HashMap<String, String>(); returnMap.put("process", "processImageWindows"); try {//from www . j a v a 2 s . c om // Init variables String[] cmd; String executable_fileName = ""; String runtimeFile = "interviewMerge.bat"; executable_fileName = ScopeApplicationAdapter.batchFileDir + runtimeFile; cmd = new String[4]; cmd[0] = "cmd.exe"; cmd[1] = "/C"; cmd[2] = "start"; cmd[3] = executable_fileName; // log.debug("executable_fileName: "+executable_fileName); // Create the Content of the Converter Script (.bat or .sh File) String fileContent = ""; for (int k = 0; k < args.length; k++) { if (k != 0) { fileContent += " "; } fileContent += args[k]; } fileContent += ScopeApplicationAdapter.lineSeperator + "exit"; File previous = new File(executable_fileName); if (previous.exists()) { previous.delete(); } // execute the Script FileOutputStream fos = new FileOutputStream(executable_fileName); fos.write(fileContent.getBytes()); fos.close(); Runtime rt = Runtime.getRuntime(); returnMap.put("command", cmd.toString()); Process proc = rt.exec(cmd); InputStream stderr = proc.getErrorStream(); BufferedReader br = new BufferedReader(new InputStreamReader(stderr)); String line = null; String error = ""; while ((line = br.readLine()) != null) { error += line; // log.debug("line: "+line); } br.close(); returnMap.put("error", error); int exitVal = proc.waitFor(); returnMap.put("exitValue", "" + exitVal); return returnMap; } catch (Throwable t) { t.printStackTrace(); returnMap.put("error", t.getMessage()); returnMap.put("exitValue", "-1"); return returnMap; } }
From source file:magma.tools.benchmark.model.bench.SinglePlayerLauncher.java
private void runScript(String scriptName, Object[] arguments) { File workingDir = new File(path); File fullPath = new File(workingDir, scriptName); if (!validatePath(fullPath)) { return;/*w ww .j a v a 2s .c o m*/ } Object[] commands = ArrayUtils.addAll(new Object[] { "bash", fullPath.getPath() }, arguments); String command = StringUtils.join(commands, " "); System.out.println(command); Process ps = UnixCommandUtil.launch(command, null, workingDir); stdOut = new StreamBufferer(ps.getInputStream(), 5000); stdErr = new StreamBufferer(ps.getErrorStream(), 5000); }
From source file:mitm.common.tools.OpenSSLWrapperTest.java
@Test(timeout = 5000) public void testVerify() throws Exception { System.out.println("Starting testVerify"); OpenSSLWrapper wrapper = new OpenSSLWrapper(); File signedFile = new File(testDir, "clear-signed-validcertificate.eml"); X509Certificate certificate = (X509Certificate) keyStore.getCertificate("root"); wrapper.setCertificateAuthorities(certificate); Process p = wrapper.verify(signedFile); InputStream result = p.getInputStream(); String error = IOUtils.toString(p.getErrorStream(), "US-ASCII"); System.out.println(error);/* ww w . j a va2s .c o m*/ assertTrue(error.startsWith("Verification successful")); File outputFile = new File(tempDir, "openssltestverify.eml"); FileOutputStream outputStream = new FileOutputStream(outputFile); IOUtils.copy(result, outputStream); outputStream.close(); }
From source file:cz.cas.lib.proarc.common.process.AsyncProcess.java
public void kill() { Level level = isDone() ? Level.FINE : Level.WARNING; LOG.log(level, "Kill isDone: " + isDone() + ", " + cmdLine); Process process = refProcess.getAndSet(null); if (process != null) { process.destroy();/*from w w w . jav a 2 s . c o m*/ IOUtils.closeQuietly(process.getInputStream()); IOUtils.closeQuietly(process.getErrorStream()); IOUtils.closeQuietly(process.getOutputStream()); done.set(true); try { outputConsumer.join(); } catch (InterruptedException ex) { LOG.log(Level.SEVERE, null, ex); } } }
From source file:io.jmnarloch.cd.go.plugin.sbt.SbtTaskExecutor.java
private int execute(ProcessBuilder builder, JobConsoleLogger console) throws IOException, InterruptedException { Process process = null; try {/* w w w . j a va 2s .c om*/ process = builder.start(); console.readOutputOf(process.getInputStream()); console.readErrorOf(process.getErrorStream()); return process.waitFor(); } finally { if (process != null) { process.destroy(); } } }
From source file:mitm.common.tools.OpenSSLWrapperTest.java
@Test(timeout = 5000) public void testDecrypt() throws Exception { System.out.println("Starting testDecrypt"); OpenSSLWrapper wrapper = new OpenSSLWrapper(); KeyStore.PasswordProtection passwd = new KeyStore.PasswordProtection("test".toCharArray()); PrivateKeyEntry entry = (PrivateKeyEntry) keyStore.getEntry("ValidCertificate", passwd); wrapper.setPrivateKey(entry.getPrivateKey()); File encryptedFile = new File(testDir, "encrypted-validcertificate.eml"); Process p = wrapper.decrypt(encryptedFile); InputStream result = p.getInputStream(); String error = IOUtils.toString(p.getErrorStream(), "US-ASCII"); System.out.println(error);/* w w w. j a v a2 s. c o m*/ assertEquals("", error.trim()); File outputFile = new File(tempDir, "openssltestdecrypt.eml"); FileOutputStream outputStream = new FileOutputStream(outputFile); IOUtils.copy(result, outputStream); outputStream.close(); }
From source file:com.betfair.cougar.test.socket.app.JarRunner.java
protected void start(File dir, String[] extraArgs, boolean waitUntilExit) throws Exception { dir.mkdirs();/*from w ww. j a v a 2 s. c o m*/ runDir = dir; // java -jar <jarfile> String[] baseCmd = new String[] { System.getProperty("java.home") + "/bin/java", "-jar", jarFile.getAbsolutePath() }; String[] cmd = new String[baseCmd.length + extraArgs.length]; System.arraycopy(baseCmd, 0, cmd, 0, baseCmd.length); System.arraycopy(extraArgs, 0, cmd, baseCmd.length, extraArgs.length); System.out.print("Running: java -jar " + cmd[2].substring(cmd[2].lastIndexOf("/") + 1)); for (int i = 3; i < cmd.length; i++) { System.out.print(" " + cmd[i]); } System.out.println(); Process p = Runtime.getRuntime().exec(cmd, new String[0], dir); startOutputStreaming(dir, p.getInputStream(), "stdout"); startOutputStreaming(dir, p.getErrorStream(), "stderr"); if (waitUntilExit) { p.waitFor(); outputs = getOutputs(); } else { backgroundProcess = p; } }