List of usage examples for java.lang Process getErrorStream
public abstract InputStream getErrorStream();
From source file:madgik.exareme.master.queryProcessor.analyzer.fanalyzer.FederatedAnalyzer.java
private void createSample() throws Exception { System.out.println(this.statCols.keySet()); System.out.println(this.statCols.keySet().size()); for (String tableName : this.statCols.keySet()) { // if(!tableName.equals("COLLATIONS")) continue; StringBuilder mm = new StringBuilder(); int i = 0; for (String c : this.statCols.get(tableName)) { String minQuery = " (select * from " + tableName + " t where t." + c + " in (select min(t2." + c + ") from " + tableName + " t2) limit 1) "; String maxQuery = " (select * from " + tableName + " t where t." + c + " in (select max(t2." + c + ") from " + tableName + " t2) limit 1) "; if (this.vendor == Vendor.Oracle) { minQuery = " (select * from " + tableName + " t where t." + c + " in (select min(t2." + c + ") from " + tableName + " t2) and ROWNUM<2) "; maxQuery = " (select * from " + tableName + " t where t." + c + " in (select max(t2." + c + ") from " + tableName + " t2) and ROWNUM<2) "; }//from w ww . ja va 2 s . co m mm.append(minQuery).append(" UNION ALL ").append(maxQuery); if (i < this.statCols.get(tableName).size() - 1) mm.append(" UNION ALL "); i++; } String sampleQuery = ""; switch (this.vendor) { case Oracle: sampleQuery = "select * from (oracle jdbc:oracle:thin:@" + this.ip + ":" + this.port + ":" + this.dbName + " u:" + this.username + " p:" + this.password + " select * from ( select * from " + tableName + " order by dbms_random.value() ) where ROWNUM <= 1000 UNION ALL " + mm.toString() + " );"; break; case Mysql: // sampleQuery = // "select * from (mysql h:127.0.0.1 port:3306 u:root db:information_schema select * from `" // + tableName + "` order by rand() limit 1000)"; if (this.password.isEmpty()) { sampleQuery = "select * from (mysql h:" + this.ip + " port:" + this.port + " u:" + this.username + " db:" + this.dbName + " (select * from " + tableName + " order by rand() limit 1000) UNION ALL " + mm.toString() + ");"; } else { sampleQuery = "select * from (mysql h:" + this.ip + " port:" + this.port + " u:" + this.username + " p:" + this.password + " db:" + this.dbName + " (select * from " + tableName + " order by rand() limit 1000) UNION ALL " + mm.toString() + " ;"; } System.out.println("=========================="); System.out.println("==========================\n\n"); System.out.println(sampleQuery); break; case Postgres: // select * from (postgres h:127.0.0.1 port:5432 u:root p:rootpw // db:testdb select 5 as num, 'test' as text); sampleQuery = "select * from (postgres h:" + this.ip + " port:" + this.port + " u:" + this.username + " p:" + this.password + " db:" + this.dbName + " (select * from " + tableName + " order by random() limit 1000) UNION ALL " + mm.toString() + ");"; // break; } String command = "echo \"create table " + tableName + " as " + sampleQuery + "\" | " + PYTHON_PATH + " " + MADIS_PATH + " " + TMP_SAMPLE_DIR + tableName + ".db"; // hugeCommand.append(command); // if(j < this.statCols.keySet().size() - 1) // hugeCommand.append(" ; "); String[] cmd = { "/bin/sh", "-c", command }; Process process = Runtime.getRuntime().exec(cmd); process.waitFor(); BufferedReader dbr = new BufferedReader(new InputStreamReader(process.getErrorStream())); String s; while ((s = dbr.readLine()) != null) { System.out.println(s); } // System.out.println(command); System.out.println("ENDED: " + tableName); System.out.println(sampleQuery); // gatherStats(); // break; } // System.out.println(hugeCommand.toString()); // String[] cmd = {"/bin/sh", "-c", hugeCommand.toString()}; // Process process = Runtime.getRuntime().exec(cmd); // process.waitFor(); }
From source file:org.zenoss.app.metric.zapp.ManagedReporter.java
String exectHostname() throws InterruptedException { int exit;//w ww .ja va2s .c o 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; }
From source file:com.samsung.sjs.ABackendTest.java
public void compilerTest(BiFunction<CompilerOptions, String[], Process> compiler, Function<String, Process> evaluator, boolean execute_code, boolean verbose, String... extra) { try {//from w w w.j av a 2 s . c o m String script = getInputScriptPath(); System.out.println("Looking for test script: " + script); System.err.println("COMPILING: " + script); File scriptfile = new File(script); Path tmpdir = Files.createTempDirectory("__fawefwea8ew"); tmpdir.toFile().deleteOnExit(); String ccode = scriptfile.getName().replaceFirst(".js$", ".c"); File cfile = File.createTempFile("___", ccode, tmpdir.toFile()); String exec = ccode.replaceFirst(".c$", ""); File execfile = File.createTempFile("___", exec, tmpdir.toFile()); CompilerOptions opts = new CompilerOptions(CompilerOptions.Platform.Native, scriptfile.getAbsolutePath(), verbose, // -debugcompiler cfile.getAbsolutePath(), true /* use GC */, "clang", "emcc", execfile.getAbsolutePath(), baseDirectory(), false /* don't dump C compiler spew into JUnit console */, true /* apply field optimizations */, verbose /* emit type inference constraints to console */, verbose /* dump constraint solution to console */, null /* find runtime src for linking locally (not running from jar) */, shouldEncodeValues(), false /* TODO: x86Test passes explicit -m32 flag, rather than setting this */, false /* we don't care about error explanations */, null /* we don't care about error explanations */, false /* generate efl environment code */, 3 /* pass C compiler -O3 */); if (doInterop()) { opts.enableInteropMode(); } if (bootInterop()) { opts.startInInteropMode(); } Compiler.compile(opts); Process clang = compiler.apply(opts, extra); clang.waitFor(); if (clang.exitValue() != 0) { StringWriter w_stdout = new StringWriter(), w_stderr = new StringWriter(); IOUtils.copy(clang.getInputStream(), w_stdout, Charset.defaultCharset()); IOUtils.copy(clang.getErrorStream(), w_stderr, Charset.defaultCharset()); String compstdout = w_stdout.toString(); String compstderr = w_stderr.toString(); System.err.println("!!!!!!!!!!!!! Compiler exited with value " + clang.exitValue()); System.err.println("Compiler stdout: " + compstdout); System.err.println("Compiler stderr: " + compstderr); } assertTrue(clang.exitValue() == 0); if (execute_code) { File prefixedscript = prefixJS(tmpdir, scriptfile); assertSameProcessOutput(runNode(prefixedscript), evaluator.apply(execfile.getAbsolutePath())); } } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
From source file:net.timbusproject.extractors.debiansoftwareextractor.Engine.java
private Properties doCommand(String command) throws InterruptedException, JSchException, IOException { if (isSsh())//from w ww. j a va2 s .c om return sshManager.sendCommand(command); Properties properties = new Properties(); Process process = new ProcessBuilder("/bin/sh", "-c", command).start(); StringWriter writer = new StringWriter(); IOUtils.copy(process.getInputStream(), writer); properties.setProperty("stdout", writer.toString()); IOUtils.copy(process.getErrorStream(), writer); properties.setProperty("stderr", writer.toString()); properties.setProperty("exit-value", String.valueOf(process.waitFor())); process.destroy(); if (Integer.parseInt(properties.getProperty("exit-value")) != 0) log.warn("command \"" + command.split(" ")[0] + "\" failed with status: " + properties.getProperty("exit-value")); return properties; }
From source file:net.sourceforge.vulcan.ant.AntBuildTool.java
/** * Subclasses may override this method to perform custom handling of * I/O. The default behavior is to close all streams. *///from w w w . j a va2 s . c o m protected void preparePipes(final Process process) throws IOException { process.getOutputStream().close(); process.getInputStream().close(); process.getErrorStream().close(); }
From source file:de.berg.systeme.jenkins.wix.WixCommand.java
/** * executes command and parses the output checking for errors. * @return true if execution was successful otherwise false. * @throws Exception//from w ww . j a va 2 s.com * @throws ToolsetException */ public boolean execute() throws Exception, ToolsetException { // false berschreibt immer true boolean success = true; String line = null; this.createCommand(); Process p = Runtime.getRuntime().exec(cmd.toString()); BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); // Log stdout of executable while ((line = stdout.readLine()) != null) { lg.log(line); success &= checkForErrors(line); } stdout.close(); // Log stderr of executable while ((line = stderr.readLine()) != null) { lg.log(line); success &= checkForErrors(line); } stderr.close(); // Wait for the process to end p.waitFor(); success &= (p.exitValue() > 0); return !success; // inverted logic at this point }
From source file:com.opensmile.maven.openSMILEclassifier.java
@Override public JSONObject classify(String audioFile) { String line = ""; String fullLine = ""; try {/* w w w .jav a 2s .c o m*/ String str = paths.SMILExtractDir + "SMILExtract " + " -C " + paths.SMILExtractDir + configFile + " -I " + audioFile + " -l 1"; Process p = Runtime.getRuntime().exec(str, null, new File(paths.SMILExtractDir)); logger_instance.write(1, "opensmile command: " + str); p.waitFor(); logger_instance.write(1, "opensmile command performed"); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = in.readLine()) != null) fullLine = fullLine + line; in = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((line = in.readLine()) != null) fullLine = fullLine + line; logger_instance.write(1, "opensmile output:" + fullLine); } catch (IOException | InterruptedException e) { e.printStackTrace(); } JSONObject jo = new JSONObject(fullLine); JSONObject jop = new JSONObject(); switch ((String) jo.get("TYPE")) { case "regression": double out = jo.getDouble("VALUE"); double conf = (double) ((JSONObject) jo.getJSONArray("PROB").get(0)).get("CONFIDENCE"); jop = createJsonEntry(entry, out); break; case "classification": jop = createJsonEntry(entry, jo.getJSONArray("PROB")); break; } return jop; }
From source file:annis.visualizers.component.AbstractDotVisualizer.java
public void writeOutput(VisualizerInput input, OutputStream outstream) { StringBuilder dot = new StringBuilder(); try {/*w ww . j a v a 2 s .c o m*/ File tmpInput = File.createTempFile("annis-dot-input", ".dot"); tmpInput.deleteOnExit(); // write out input file StringBuilder dotContent = new StringBuilder(); createDotContent(input, dotContent); FileUtils.writeStringToFile(tmpInput, dotContent.toString()); // execute dot String dotPath = input.getMappings().getProperty("dotpath", "dot"); ProcessBuilder pBuilder = new ProcessBuilder(dotPath, "-Tpng", tmpInput.getCanonicalPath()); pBuilder.redirectErrorStream(false); Process process = pBuilder.start(); InputStream inputFromProcess = process.getInputStream(); for (int chr = inputFromProcess.read(); chr != -1; chr = inputFromProcess.read()) { outstream.write(chr); } inputFromProcess.close(); int resultCode = process.waitFor(); if (resultCode != 0) { InputStream stderr = process.getErrorStream(); StringBuilder errorMessage = new StringBuilder(); for (int chr = stderr.read(); chr != -1; chr = stderr.read()) { errorMessage.append((char) chr); } if (!"".equals(errorMessage.toString())) { log.error( "Could not execute dot graph-layouter.\ncommand line:\n{}\n\nstderr:\n{}\n\nstdin:\n{}", new Object[] { StringUtils.join(pBuilder.command(), " "), errorMessage.toString(), dot.toString() }); } } // cleanup if (!tmpInput.delete()) { log.warn("Cannot delete " + tmpInput.getAbsolutePath()); } } catch (Exception ex) { log.error(null, ex); } }
From source file:com.jstar.eclipse.services.ConsoleService.java
public void printToConsole(JavaFile selectedFile, Process pr) throws IOException, JSONException, InterruptedException, CoreException { MessageConsole myConsole = getConsole(); MessageConsoleStream out = myConsole.newMessageStream(); List<VerificationError> errors = new LinkedList<VerificationError>(); StreamThread errorGobbler = new StreamThread(pr.getErrorStream(), errors); StreamThread outputGobbler = new StreamThread(pr.getInputStream(), errors); errorGobbler.start();// w w w . j ava 2 s. co m outputGobbler.start(); errorGobbler.join(); outputGobbler.join(); int exitVal = pr.waitFor(); if (exitVal != 0) { out.println("Exited with error code " + exitVal); } for (VerificationError error : errors) { if (error != null) { IMarker marker = selectedFile.createMarker(VerificationError.JSTAR_ERROR_MARKER); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); final ErrorPosition errorOffset = selectedFile.getErrorPosition(error.getStartLine(), error.getEndLine(), error.getStartPos(), error.getEndPos()); marker.setAttribute(IMarker.CHAR_START, errorOffset.getStartPos()); marker.setAttribute(IMarker.CHAR_END, errorOffset.getEndPos()); marker.setAttribute(IMarker.MESSAGE, error.getError_message()); } } showConsole(); }
From source file:com.adito.boot.Util.java
/** * Attempt to make a file executable. Only current works on * systems that have the <b>chmod</b> command available. * /*from w ww .ja v a2 s . com*/ * @param binLocation * @throws IOException on any error */ public static void makeExecutable(File binLocation) throws IOException { Process p = Runtime.getRuntime().exec(new String[] { "chmod", "ug+rx", binLocation.getAbsolutePath() }); try { copy(p.getErrorStream(), new ByteArrayOutputStream()); } finally { try { if (p.waitFor() != 0) { throw new IOException("Failed to set execute permission. Return code " + p.exitValue() + "."); } } catch (InterruptedException e) { } } }