List of usage examples for java.lang Process getOutputStream
public abstract OutputStream getOutputStream();
From source file:com.att.android.arodatacollector.main.AROCollectorService.java
/** * Starts the video capture of the device desktop by reading frame buffer * using ffmpeg command/* w ww .ja va 2s . com*/ */ private void startScreenVideoCapture() { Process sh = null; DataOutputStream os = null; try { if (DEBUG) { Log.e(TAG, "Starting Video Capture"); } sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); String Command = "cd " + ARODataCollector.INTERNAL_DATA_PATH + " \n"; os.writeBytes(Command); Command = "chmod 777 ffmpeg \n"; os.writeBytes(Command); Command = "./ffmpeg -f fbdev -vsync 2 -r 3 -i /dev/graphics/fb0 /sdcard/ARO/" + TRACE_FOLDERNAME + "/video.mp4 2> /data/ffmpegout.txt \n"; os.writeBytes(Command); Command = "exit\n"; os.writeBytes(Command); os.flush(); sh.waitFor(); } catch (IOException e) { Log.e(TAG, "exception in startScreenVideoCapture", e); } catch (InterruptedException e) { Log.e(TAG, "exception in startScreenVideoCapture", e); } finally { try { if (DEBUG) { Log.e(TAG, "Stopped Video Capture in startScreenVideoCapture"); } os.close(); // Reading start time of Video from ffmpegout file mApp.readffmpegStartTimefromFile(); } catch (IOException e) { Log.e(TAG, "IOException in reading video start time", e); } catch (NumberFormatException e) { Log.e(TAG, "NumberFormatException in reading video start time", e); } try { // Recording start time of video mApp.writeVideoTraceTime(Double.toString(mApp.getAROVideoCaptureStartTime())); mApp.closeVideoTraceTimeFile(); } catch (IOException e) { Log.e(TAG, "IOException in writing video start time", e); } if (mApp.getTcpDumpStartFlag() && !mApp.getARODataCollectorStopFlag()) { mApp.setVideoCaptureFailed(true); } try { mApp.setAROVideoCaptureRunningFlag(false); sh.destroy(); } catch (Exception e) { Log.e(TAG, "Failed to destroy shell during Video Capture termination"); } } }
From source file:org.exist.xquery.modules.mail.SendEmailFunction.java
/** * Sends an email using the Operating Systems sendmail application * * @param mail representation of the email to send * @return boolean value of true of false indicating success or failure to send email *//* w ww . j ava2 s. c om*/ private boolean sendBySendmail(Mail mail) { PrintWriter out = null; try { //Create a list of all Recipients, should include to, cc and bcc recipient List<String> allrecipients = new ArrayList<String>(); allrecipients.addAll(mail.getTo()); allrecipients.addAll(mail.getCC()); allrecipients.addAll(mail.getBCC()); //Get a string of all recipients email addresses String recipients = ""; for (int x = 0; x < allrecipients.size(); x++) { //Check format of to address does it include a name as well as the email address? if (((String) allrecipients.get(x)).indexOf("<") != -1) { //yes, just add the email address recipients += " " + ((String) allrecipients.get(x)).substring( ((String) allrecipients.get(x)).indexOf("<") + 1, ((String) allrecipients.get(x)).indexOf(">")); } else { //add the email address recipients += " " + ((String) allrecipients.get(x)); } } //Create a sendmail Process Process p = Runtime.getRuntime().exec("/usr/sbin/sendmail" + recipients); //Get a Buffered Print Writer to the Processes stdOut out = new PrintWriter(new OutputStreamWriter(p.getOutputStream(), charset)); //Send the Message writeMessage(out, mail); } catch (IOException e) { LOG.error(e.getMessage(), e); return false; } finally { //Close the stdOut if (out != null) out.close(); } //Message Sent Succesfully LOG.info("send-email() message sent using Sendmail " + new Date()); return true; }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param restoreFilePath//from ww w. jav a 2s . c o m * @param mysqlLoc * @param databaseName * @return */ public boolean doRestore(final String restoreFilePath, final String mysqlLoc, final String databaseName, final String userName, final String password) { FileInputStream input = null; try { Vector<String> args = new Vector<String>(); args.add(mysqlLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); //Thread.sleep(100); OutputStream out = process.getOutputStream(); // wait as long it takes till the other process has prompted. try { File inFile = new File(restoreFilePath); input = new FileInputStream(inFile); try { //long totalBytes = 0; byte[] bytes = new byte[8192 * 4]; // 32K do { int numBytes = input.read(bytes, 0, bytes.length); //totalBytes += numBytes; //System.out.println(numBytes+" / "+totalBytes); if (numBytes > 0) { out.write(bytes, 0, numBytes); } else { break; } } while (true); } finally { input.close(); } } catch (IOException ex) { ex.printStackTrace(); errorMsg = ex.toString(); return false; } catch (Exception ex) { ex.printStackTrace(); return false; } finally { out.flush(); out.close(); } BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.err.println(line); } in = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { if (line.startsWith("ERR")) { sb.append(line); sb.append("\n"); } } errorMsg = sb.toString(); //System.out.println("errorMsg: ["+errorMsg+"]"); return errorMsg == null || errorMsg.isEmpty(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); } return false; }
From source file:org.pshdl.model.simulation.codegenerator.DartCodeGenerator.java
public IHDLInterpreterFactory<NativeRunner> createInterpreter(final File tempDir) { try {/*from ww w . j a v a 2 s. co m*/ IHDLInterpreterFactory<NativeRunner> _xblockexpression = null; { final String dartCode = this.generateMainCode(); final File binDir = new File(tempDir, "bin"); boolean _mkdirs = binDir.mkdirs(); boolean _not = (!_mkdirs); if (_not) { throw new IllegalArgumentException(("Failed to create Directory " + binDir)); } File _file = new File(binDir, "dut.dart"); Files.write(dartCode, _file, StandardCharsets.UTF_8); final File testRunnerDir = new File(DartCodeGenerator.TESTRUNNER_DIR); final File testRunner = new File(testRunnerDir, "bin/darttestrunner.dart"); String _name = testRunner.getName(); File _file_1 = new File(binDir, _name); Files.copy(testRunner, _file_1); final File yaml = new File(testRunnerDir, "pubspec.yaml"); String _name_1 = yaml.getName(); File _file_2 = new File(tempDir, _name_1); Files.copy(yaml, _file_2); File _file_3 = new File(binDir, "packages"); Path _path = _file_3.toPath(); File _file_4 = new File(testRunnerDir, "packages"); Path _path_1 = _file_4.toPath(); java.nio.file.Files.createSymbolicLink(_path, _path_1); File _file_5 = new File(tempDir, "packages"); Path _path_2 = _file_5.toPath(); File _file_6 = new File(testRunnerDir, "packages"); Path _path_3 = _file_6.toPath(); java.nio.file.Files.createSymbolicLink(_path_2, _path_3); _xblockexpression = new IHDLInterpreterFactory<NativeRunner>() { public NativeRunner newInstance() { try { String _name = testRunner.getName(); String _plus = ("bin/" + _name); ProcessBuilder _processBuilder = new ProcessBuilder(DartCodeGenerator.DART_EXEC, _plus, DartCodeGenerator.this.unitName, DartCodeGenerator.this.library); ProcessBuilder _directory = _processBuilder.directory(tempDir); ProcessBuilder _redirectErrorStream = _directory.redirectErrorStream(true); final Process dartRunner = _redirectErrorStream.start(); InputStream _inputStream = dartRunner.getInputStream(); OutputStream _outputStream = dartRunner.getOutputStream(); return new NativeRunner(_inputStream, _outputStream, DartCodeGenerator.this.em, dartRunner, 5, ((("Dart " + DartCodeGenerator.this.library) + ".") + DartCodeGenerator.this.unitName)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } }; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:edu.ku.brc.af.core.db.MySQLBackupService.java
/** * @param databaseName//from ww w . ja v a 2s . co m * @param restoreFilePath * @param glassPane * @param completionMsgKey */ protected boolean doRestoreInBackground(final String databaseName, final String restoreFilePath, final SimpleGlassPane glassPane, final String completionMsgKey, final PropertyChangeListener pcl, final boolean doSynchronously) { AppPreferences remotePrefs = AppPreferences.getLocalPrefs(); final String mysqlLoc = remotePrefs.get(MYSQL_LOC, getDefaultMySQLLoc()); getNumberofTables(); SynchronousWorker backupWorker = new SynchronousWorker() { long dspMegs = 0; long fileSize = 0; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { FileInputStream input = null; try { String userName = itUsername != null ? itUsername : DBConnection.getInstance().getUserName(); String password = itPassword != null ? itPassword : DBConnection.getInstance().getPassword(); String port = DatabaseDriverInfo.getDriver(DBConnection.getInstance().getDriverName()) .getPort(); String server = DBConnection.getInstance().getServerName(); String cmdLine = String.format("%s -u %s --password=%s --host=%s %s %s", mysqlLoc, userName, password, server, (port != null ? ("--port=" + port) : ""), databaseName); Vector<String> args = new Vector<String>(); args.add(mysqlLoc); args.add("--user=" + userName); args.add("--password=" + password); args.add("--host=" + server); if (port != null) { args.add("--port=" + port); } args.add(databaseName); Process process = Runtime.getRuntime().exec(args.toArray(new String[0])); Thread.sleep(100); OutputStream out = process.getOutputStream(); // wait as long it takes till the other process has prompted. try { File inFile = new File(restoreFilePath); fileSize = inFile.length(); //System.out.println(fileSize); double oneMB = (1024.0 * 1024.0); double threshold = fileSize < (oneMB * 4) ? 8192 * 8 : oneMB; long totalBytes = 0; dspMegs = 0; input = new FileInputStream(inFile); try { byte[] bytes = new byte[8192 * 4]; do { int numBytes = input.read(bytes, 0, bytes.length); totalBytes += numBytes; if (numBytes > 0) { out.write(bytes, 0, numBytes); long megs = (long) (totalBytes / threshold); if (megs != dspMegs) { dspMegs = megs; firePropertyChange(MEGS, dspMegs, (int) ((100.0 * totalBytes) / fileSize)); } } else { break; } } while (true); } finally { input.close(); } } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MySQLBackupService.class, ex); ex.printStackTrace(); errorMsg = ex.toString(); UIRegistry.showLocalizedError("MySQLBackupService.EXCP_RS"); } catch (Exception ex) { ex.printStackTrace(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } setProgress(100); out.flush(); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; while ((line = in.readLine()) != null) { //System.err.println(line); } in = new BufferedReader(new InputStreamReader(process.getErrorStream())); StringBuilder sb = new StringBuilder(); while ((line = in.readLine()) != null) { if (line.startsWith("ERR")) { sb.append(line); sb.append("\n"); } } errorMsg = sb.toString(); } catch (Exception ex) { ex.printStackTrace(); errorMsg = ex.toString(); if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, ERROR, 0, 1)); } } return null; } @Override protected void done() { super.done(); JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { statusBar.setProgressDone(STATUSBAR_NAME); } if (glassPane != null) { UIRegistry.clearSimpleGlassPaneMsg(); } if (StringUtils.isNotEmpty(errorMsg)) { UIRegistry.showError(errorMsg); } if (statusBar != null) { statusBar.setText(UIRegistry.getLocalizedMessage(completionMsgKey, dspMegs)); } if (pcl != null) { pcl.propertyChange(new PropertyChangeEvent(MySQLBackupService.this, DONE, 0, 1)); } } }; if (glassPane != null) { glassPane.setProgress(0); } backupWorker.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { if (MEGS.equals(evt.getPropertyName()) && glassPane != null) { int value = (Integer) evt.getNewValue(); if (value < 100) { glassPane.setProgress((Integer) evt.getNewValue()); } else { glassPane.setProgress(100); } } } }); if (doSynchronously) { return backupWorker.doWork(); } backupWorker.execute(); return true; }
From source file:org.pentaho.di.job.entries.pgpencryptfiles.GPG.java
/** * Runs GnuPG external program/*from w w w .j a va 2 s . co m*/ * * @param commandArgs * command line arguments * @param inputStr * key ID of the key in GnuPG's key database * @param fileMode * @return result * @throws KettleException */ private String execGnuPG(String commandArgs, String inputStr, boolean fileMode) throws KettleException { Process p; String command = getGpgExeFile() + " " + (fileMode ? "" : gnuPGCommand + " ") + commandArgs; if (log.isDebug()) { log.logDebug(BaseMessages.getString(PKG, "GPG.RunningCommand", command)); } String retval; try { if (Const.isWindows()) { p = Runtime.getRuntime().exec(command); } else { ProcessBuilder processBuilder = new ProcessBuilder("/bin/sh", "-c", command); p = processBuilder.start(); } } catch (IOException io) { throw new KettleException(BaseMessages.getString(PKG, "GPG.IOException"), io); } ProcessStreamReader psr_stdout = new ProcessStreamReader(p.getInputStream()); ProcessStreamReader psr_stderr = new ProcessStreamReader(p.getErrorStream()); psr_stdout.start(); psr_stderr.start(); if (inputStr != null) { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); try { out.write(inputStr); } catch (IOException io) { throw new KettleException(BaseMessages.getString(PKG, "GPG.ExceptionWrite"), io); } finally { if (out != null) { try { out.close(); } catch (Exception e) { // Ignore } } } } try { p.waitFor(); psr_stdout.join(); psr_stderr.join(); } catch (InterruptedException i) { throw new KettleException(BaseMessages.getString(PKG, "GPG.ExceptionWait"), i); } try { if (p.exitValue() != 0) { throw new KettleException( BaseMessages.getString(PKG, "GPG.Exception.ExistStatus", psr_stderr.getString())); } } catch (IllegalThreadStateException itse) { throw new KettleException(BaseMessages.getString(PKG, "GPG.ExceptionillegalThreadStateException"), itse); } finally { p.destroy(); } retval = psr_stdout.getString(); return retval; }
From source file:net.emotivecloud.scheduler.drp4ost.OStackClient.java
public String createImage(OVFDisk disk, String pathLocalBaseImage) { // disk_format=qcow2 //The disk_format field specifies the format of the image file. In this case, the image file format is QCOW2, which can be verified using the file command: ////from w ww .j a v a2s . c o m //$ file stackimages/cirros.img //Other valid formats are raw, vhd, vmdk, vdi, iso, aki, ari and ami. // container-format=bare //The container-format field is required by the glance image-create command but isn't actually used by any of the OpenStack services, so the value specified here has no effect on system behavior. We specify bare to indicate that the image file is not in a file format that contains metadata about the virtual machine. // //Because the value is not used anywhere, it safe to always specify bare as the container format, although the command will accept other formats: ovf, aki, ari, ami. // glance image-create --name centos63-image --disk-format=qcow2 --container-format=raw --is-public=True < ./centos63.qcow2 // glance add name=cirros-0.3.0-x86_64 disk_format=qcow2 container_format=bare < stackimages/cirros.img System.out.println( "DRP4OST-this.createImage()> disk.getHref()=" + disk.getHref() + "disk.getId()" + disk.getId()); String imagePath = disk.getHref(); //"/home/smendoza/cirros-0.3.0-x86_64-disk.img"; String name = imagePath.trim().substring(imagePath.lastIndexOf("/") + 1, imagePath.length()); // String name = disk.getId(); // String name = disk.getId() + "_" + (new Random()).nextInt(99999999); String diskFormat = "qcow2"; // permitted: img, raw, vhd, vmdk, vdi, iso, aki, ari and ami boolean download = false; String openStackID = null; try { // execution of the add command // Process p = Runtime.getRuntime().exec(cmdAdd, env); // Obtained the arguments from 'glance help add' ArrayList<String> myCmd = new ArrayList<String>(); myCmd.add("glance"); myCmd.add("add"); // myCmd.add(String.format("id=%s", disk.getId())); myCmd.add(String.format("name=%s", name)); myCmd.add(String.format("disk_format=%s", diskFormat)); myCmd.add(String.format("container_format=%s", this.IMG_DEFAULT_CONTAINER_FORMAT)); myCmd.add(String.format("is_public=%s", this.IMG_DEFAULT_IS_PUBLIC)); if (disk.getHref().startsWith("http://")) { //The image has been already downloaded and merged, and is staying at pathLocalBaseImage imagePath = pathLocalBaseImage; download = false; } else { // App will add the full path download = false; if (!disk.getHref().startsWith("/")) { //Incomplete path, necessary to add default path (img.default.path parameter) imagePath = this.IMG_DEFAULT_PATH + "/" + imagePath; } else { //Complete path (expected), not necessary to add nothing } } ProcessBuilder pb = new ProcessBuilder(myCmd); pb.redirectErrorStream(true); // Set up the environment to communicate with OpenStack Map<String, String> envir = pb.environment(); envir.put("OS_AUTH_URL", this.OS_AUTH_URL); envir.put("OS_TENANT_ID", this.OS_TENANT_ID); envir.put("OS_TENANT_NAME", this.OS_TENANT_NAME); envir.put("OS_USERNAME", this.OS_USERNAME); envir.put("OS_PASSWORD", this.OS_PASSWORD); // Execute the command specified with its environment Process p = pb.start(); InputStream pis = p.getInputStream(); // if image not downloaded, it will have to uploaded if (!download) { OutputStream pos = p.getOutputStream(); File imgFile = new File(imagePath); System.out.println("DRP4OST-OStackClient.createImage()> START UPLOADING (" + imgFile.getPath() + ") TO OPENSTACK REPOSITORY"); if (imgFile.exists()) { InputStream fis = new FileInputStream(imgFile); byte[] buffer = new byte[1024]; int read = 0; while ((read = fis.read(buffer)) != -1) { pos.write(buffer, 0, read); } // Close the file stream fis.close(); System.out.println("DRP4OST-OStackClient.createImage()> FINISH UPLOADING (" + imgFile.getPath() + ")TO OPENSTACK REPOSITORY"); } else { System.out.println("DRP4OST-OStackClient.createImage()> The file " + imgFile.getPath() + " does not exist! Abort VM creation!"); throw new Exception("DRP4OST-OStackClient.createImage()> The file " + imgFile.getPath() + " does not exist! Abort VM instance creation!"); } // Close the process stream. If not, OpenStack keeps the image at "Saving" status pos.close(); } else { System.out.println( "DRP4OST-OStackClient.createImage()> The image is expected to be download automatically by OpenStack-glance from " + imagePath); } System.out.println("DRP4OST-OStackClient.createImage()> glance output: " + ImageMerge.ISToString(pis)); pis.close(); openStackID = getImageID(name); System.out.println("DRP4OST-OStackClient.createImage()> getImageStatus(" + openStackID + ")=" + getImageStatus(openStackID)); // Wait while hte image is not ready to be used while (!getImageStatus(openStackID).equals("ACTIVE")) { System.out.println("DRP4OST-OStackClient.createImage()> getImageStatus(" + openStackID + ")=" + getImageStatus(openStackID)); Thread.sleep(1000); } } catch (Exception e) { e.printStackTrace(); throw new DRPOSTException("Exception creating the image", StatusCodes.BAD_REQUEST); } return openStackID; }
From source file:ch.kostceco.tools.siardexcerpt.excerption.moduleexcerpt.impl.ExcerptBSearchModuleImpl.java
@Override public boolean validate(File siardDatei, File outFileSearch, String searchString) throws ExcerptBSearchException { boolean isValid = true; File fGrepExe = new File("resources" + File.separator + "grep" + File.separator + "grep.exe"); String pathToGrepExe = fGrepExe.getAbsolutePath(); if (!fGrepExe.exists()) { // grep.exe existiert nicht --> Abbruch getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B) + getTextResourceService().getText(ERROR_XML_C_MISSINGFILE, fGrepExe.getAbsolutePath())); return false; } else {//ww w . ja v a 2 s. co m File fMsys10dll = new File("resources" + File.separator + "grep" + File.separator + "msys-1.0.dll"); if (!fMsys10dll.exists()) { // msys-1.0.dll existiert nicht --> Abbruch getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B) + getTextResourceService().getText(ERROR_XML_C_MISSINGFILE, fMsys10dll.getAbsolutePath())); return false; } } File tempOutFile = new File(outFileSearch.getAbsolutePath() + ".tmp"); String content = ""; String contentAll = ""; // Records aus table herausholen try { if (tempOutFile.exists()) { Util.deleteDir(tempOutFile); } /* Nicht vergessen in "src/main/resources/config/applicationContext-services.xml" beim * entsprechenden Modul die property anzugeben: <property name="configurationService" * ref="configurationService" /> */ String name = getConfigurationService().getSearchtableName(); String folder = getConfigurationService().getSearchtableFolder(); File fSearchtable = new File(siardDatei.getAbsolutePath() + File.separator + "content" + File.separator + "schema0" + File.separator + folder + File.separator + folder + ".xml"); searchString = searchString.replaceAll("\\.", "\\.*"); try { // grep -E "REGEX-Suchbegriff" table13.xml >> output.txt String command = "cmd /c \"" + pathToGrepExe + " -E \"" + searchString + "\" " + fSearchtable.getAbsolutePath() + " >> " + tempOutFile.getAbsolutePath() + "\""; /* Das redirect Zeichen verunmglicht eine direkte eingabe. mit dem geschachtellten Befehl * gehts: cmd /c\"urspruenlicher Befehl\" */ // System.out.println( command ); Process proc = null; Runtime rt = null; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_ELEMENT_OPEN, name)); try { Util.switchOffConsole(); rt = Runtime.getRuntime(); proc = rt.exec(command.toString().split(" ")); // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden ist! // Fehleroutput holen StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR"); // Output holen StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT"); // Threads starten errorGobbler.start(); outputGobbler.start(); // Warte, bis wget fertig ist proc.waitFor(); Util.switchOnConsole(); } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); return false; } finally { if (proc != null) { closeQuietly(proc.getOutputStream()); closeQuietly(proc.getInputStream()); closeQuietly(proc.getErrorStream()); } } Scanner scanner = new Scanner(tempOutFile); contentAll = ""; content = ""; contentAll = scanner.useDelimiter("\\Z").next(); scanner.close(); content = contentAll; /* im contentAll ist jetzt der Gesamtstring, dieser soll anschliessend nur noch aus den 4 * Such-Zellen und den weiteren 4 ResultateZellen bestehen -> content */ String nr1 = getConfigurationService().getcellNumber1(); String nr2 = getConfigurationService().getcellNumber2(); String nr3 = getConfigurationService().getcellNumber3(); String nr4 = getConfigurationService().getcellNumber4(); String nr5 = getConfigurationService().getcellNumberResult1(); String nr6 = getConfigurationService().getcellNumberResult2(); String nr7 = getConfigurationService().getcellNumberResult3(); String nr8 = getConfigurationService().getcellNumberResult4(); String cellLoop = ""; // Loop von 1, 2, 3 ... bis 499999. for (int i = 1; i < 500000; i++) { cellLoop = ""; cellLoop = "c" + i; if (cellLoop.equals(nr1) || cellLoop.equals(nr2) || cellLoop.equals(nr3) || cellLoop.equals(nr4) || cellLoop.equals(nr5) || cellLoop.equals(nr6) || cellLoop.equals(nr7) || cellLoop.equals(nr8)) { // wird behalten } else { String deletString = "<c" + i + ">" + ".*" + "</c" + i + ">"; content = content.replaceAll(deletString, ""); } } getMessageService() .logError(getTextResourceService().getText(MESSAGE_XML_ELEMENT_CONTENT, content)); getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_ELEMENT_CLOSE, name)); if (tempOutFile.exists()) { Util.deleteDir(tempOutFile); } contentAll = ""; content = ""; // Ende Grep } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); return false; } } catch (Exception e) { getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_B) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); return false; } return isValid; }
From source file:org.fusesource.meshkeeper.distribution.provisioner.embedded.Execute.java
/** * Starts a process defined by the command line. * Ant will not wait for this process, nor log its output. * * @throws java.io.IOException The exception is thrown, if launching * of the subprocess failed.//from ww w . j av a 2 s . c om * @since Ant 1.6 */ public void spawn() throws IOException { createWorkingDir(); final Process process = launch(getCommandline(), getEnvironment(), workingDirectory, useVMLauncher); if (Os.isFamily("windows")) { try { Thread.sleep(ONE_SECOND); } catch (InterruptedException e) { LOG.debug("interruption in the sleep after having spawned a" + " process"); } } OutputStream dummyOut = new OutputStream() { public void write(int b) throws IOException { // Method intended to swallow whatever comes at it } }; ExecuteStreamHandler handler = new PumpStreamHandler(dummyOut); handler.setProcessErrorStream(process.getErrorStream()); handler.setProcessOutputStream(process.getInputStream()); handler.start(); process.getOutputStream().close(); }
From source file:com.att.android.arodatacollector.main.AROCollectorService.java
/** * issue the kill -9 command if ffmpeg couldn't be stopped with kill -15 *///from w w w .j av a2 s . c o m private void kill9Ffmpeg() { Process sh = null; DataOutputStream os = null; int pid = 0, exitValue = -1; try { //have a 1 sec delay since it takes some time for the kill -15 to end ffmpeg Thread.sleep(1000); pid = mAroUtils.getProcessID("ffmpeg"); if (pid != 0) { //ffmpeg still running if (DEBUG) { Log.i(TAG, "ffmpeg still running after kill -15. Will issue kill -9 " + pid); } sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); String Command = "kill -9 " + pid + "\n"; os.writeBytes(Command); Command = "exit\n"; os.writeBytes(Command); os.flush(); //clear the streams so that it doesnt block the process //sh.inputStream is actually the output from the process StreamClearer stdoutClearer = new StreamClearer(sh.getInputStream(), "stdout", false); new Thread(stdoutClearer).start(); StreamClearer stderrClearer = new StreamClearer(sh.getErrorStream(), "stderr", true); new Thread(stderrClearer).start(); exitValue = sh.waitFor(); if (exitValue == 0) { mVideoRecording = false; } else { Log.e(TAG, "could not kill ffmpeg in kill9Ffmpeg, exitValue=" + exitValue); } } else { mVideoRecording = false; if (DEBUG) { Log.i(TAG, "ffmpeg had been ended successfully by kill -15"); } } } catch (Exception e1) { Log.e(TAG, "exception in kill9Ffmpeg", e1); } finally { try { if (os != null) { os.close(); } if (sh != null) { sh.destroy(); } } catch (Exception e) { Log.e(TAG, "exception in kill9Ffmpeg DataOutputStream close", e); } } }