public static void indexMediaFiles () { try { // create a new array of 2 strings String[] cmdArray = new String[2]; // first argument is the program we want to open cmdArray[0] = "python3"; // second argument is a txt file we want to open with notepad cmdArray[1] = "./media/only_indexing.py"; // print a message System.out.println("Indexing...."); // create a process and execute cmdArray and currect environment Process process = Runtime.getRuntime().exec(cmdArray, null); process.waitFor (); System.out.println("Indexed...."); // print another message System.out.println("should be working...."); } catch (Exception ex) { ex.printStackTrace(); } }
public static void showWeather (Stage stage, VBox panel) { try { // create a new array of 2 strings String[] cmdArray = new String[2]; // first argument is the program we want to open cmdArray[0] = "python3"; // second argument is a txt file we want to open with notepad cmdArray[1] = "weather.py"; // print a message System.out.println("Displaying weather...."); // create a process and execute cmdArray and correct environment Process process = Runtime.getRuntime().exec(cmdArray, null); process.waitFor (); } catch (Exception ex) { ex.printStackTrace(); } readWeather( stage, panel); }
/** Appends the instance to this list. Note that since memory for * the Instance has already been allocated, no check is made to * catch OutOfMemoryError. * @return <code>true</code> if successful */ public boolean add (Instance instance) { if (pipe == notYetSetPipe) pipe = instance.getPipe(); else if (instance.getPipe() != pipe) // Making sure that the Instance has the same pipe as us. // xxx This also is a good time check that the constituent data is // of a consistent type? throw new IllegalArgumentException ("pipes don't match: instance: "+ instance.getPipe()+" Instance.list: "+ this.pipe); if (dataClass == null) { dataClass = instance.data.getClass(); if (pipe != null && pipe.isTargetProcessing()) targetClass = instance.target.getClass(); } instance.setLock(); boolean ret = instances.add (instance); inMemory.set(size()-1); logger.finer ("Added instance " + (size()-1) + ". Free memory remaining (bytes): " + Runtime.getRuntime().freeMemory()); return ret; }
private void runRsync(String source, String destination, List<String> options) throws Exception { ArrayList<String> argv = new ArrayList<String>(options); String line; Process process; BufferedReader processOutput, processErrors; argv.add(0, "rsync"); argv.add(source); argv.add(destination); process = Runtime.getRuntime().exec(argv.toArray(new String[0])); processOutput = new BufferedReader(new InputStreamReader(process.getInputStream())); processErrors = new BufferedReader(new InputStreamReader(process.getErrorStream())); do { line = processOutput.readLine(); if (line != null) System.out.println(line); } while (line != null); do { line = processErrors.readLine(); if (line != null) System.out.println(line); } while (line != null); process.waitFor(); }
@RequestMapping("/iniciar-servidor") public Pc greeting() { DB db = new DB(); db.conectar(); Pc usuario = db.insertar(); db.desconectar(); if (Util.docker) { try{ Process proceso; Runtime shell = Runtime.getRuntime(); // COMANDO DOCKER // docker run -d --rm -p [PuertoPHP]:80 -p [PuertoSQL]:3306 --name=server[ID] xxdrackleroxx/test proceso = shell.exec("docker run -d --rm -p " + usuario.getPuertoPHP() + ":80 -p " + usuario.getPuertoSQL() + ":3306 --name=server" + usuario.getId() + " xxdrackleroxx/test"); proceso.waitFor(); }catch(Exception e){ System.out.println("[ERROR] Problema con shell"); } } return usuario; }
@RequestMapping("/detener-servidor") public String greeting(@RequestParam(value="id", defaultValue="-1") Integer id) { if(id != -1){ DB db = new DB(); db.conectar(); db.eliminar(id); db.desconectar(); if (Util.docker) { Process proceso; Runtime shell = Runtime.getRuntime(); try { // COMANDO DOCKER // docker run -d --rm -p [PuertoPHP]:80 -p [PuertoSQL]:3306 --name=server[ID] xxdrackleroxx/test:1.0 proceso = shell.exec("docker stop -t 0 server" + id); } catch (Exception e) { return "{\"status\":\"ERROR SHELL\"}"; } } return "{\"status\":\"OK\"}"; } return "{\"status\":\"ERROR ID\"}"; }
public static String readNews (String newsCategory) { try { System.out.println(newsCategory); // create a new array of 2 strings String[] cmdArray = new String[3]; // first argument is the program we want to open cmdArray[0] = "python"; // second argument is a txt file we want to open with notepad cmdArray[1] = "./src/main/java/app/news/news.py"; // third argument is the song to be played if(newsCategory.equals ("news")) newsCategory = "fav"; cmdArray[2] = newsCategory; System.out.println(cmdArray[2]); // print a message System.out.println("Displaying news...."); // create a process and execute cmdArray and correct environment Process process = Runtime.getRuntime().exec(cmdArray, null); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String line, outputLine = ""; // System.out.println(in.readLine()); while ((line = in.readLine()) != null) { outputLine = line; } process.waitFor (); //response.close(); System.out.println(outputLine); return outputLine; } catch (Exception ex) { ex.printStackTrace(); } return "false"; }
public static void main(String args[])throws IOException { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter your git remote url");//Accepting URL String u=br.readLine(); URL url=new URL(u); //System.out.println("Enter your commit sentence");//Commit line String commit="make it better"; System.out.println("Get ready for your code to be on github in few minutes.."); String comd[]=new String[6]; comd[0]="git init"; comd[1]="git add ."; comd[2]="git commit -m \""+commit+"\""; comd[3]="git remote add origin "+url; comd[4]="git push -u origin master"; //comd[4]="git push -f origin master"; // Sometimes harmful to execute without user prompt for(int i=0;i<5;i++) { String cmd=comd[i]; Runtime run = Runtime.getRuntime(); Process pr = run.exec(cmd); pr.waitFor(); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = ""; while ((line=buf.readLine())!=null) { System.out.println(line); //Error handling and force push prompts has to be handled } } System.out.println("Uploaded on github.."); }catch(InterruptedException e){ } }
private static void runtool(jvm jvm, String loc, String[] args) throws IOException { System.out.println(concatenate(args) + ':'); if (jvm == null) { com.pivotal.gemfirexd.internal.iapi.tools.run.main(args); return; } Vector cmd = jvm.getCommandLine(); cmd.addElement("-jar"); cmd.addElement(loc); for (int i=0; i < args.length; i++) { cmd.addElement(args[i]); } String command = concatenate((String[]) cmd.toArray(new String[0])); Process pr = null; try { pr = Runtime.getRuntime().exec(command); BackgroundStreamSaver saver = new BackgroundStreamSaver(pr.getInputStream(), System.out); saver.finish(); pr.waitFor(); pr.destroy(); } catch(Throwable t) { System.out.println("Process exception: " + t.getMessage()); if (pr != null) { pr.destroy(); pr = null; } } }
public JSONRPC2Handler(String hostName, int port, RequestHandler h) throws Exception { int cores = Runtime.getRuntime().availableProcessors(); handler = h; server = HttpServer.create(new InetSocketAddress(InetAddress.getByName(hostName),port), 0); server.createContext("/", this); server.setExecutor(Executors.newFixedThreadPool(cores)); server.start(); }
/** * Start Tunnelblick, so that we have the required directories created */ public void startTunnelblick() { try { Runtime.getRuntime().exec(new String[] { "open", "/Applications/Tunnelblick.app" }); } catch (Exception e) { log.error("", e); } }
public static void _RegisterShutdownHook(final GraphDatabaseService db) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { db.shutdown(); } }); }
public static String playSong (String songName) { try { // create a new array of 2 strings String[] cmdArray = new String[3]; // first argument is the program we want to open cmdArray[0] = "python3"; // second argument is a txt file we want to open with notepad cmdArray[1] = "./media/song_search.py"; // third argument is the song to be played if(songName.equals ("media")) songName = "fav"; cmdArray[2] = songName; // print a message System.out.println("Playing...."); getUrl(); // create a process and execute cmdArray and correct environment Process process = Runtime.getRuntime().exec(cmdArray, null); // BufferedReader response = new BufferedReader(new InputStreamReader(process.getInputStream())); // //BufferedWriter bw = new BufferedWriter(response); // //System.out.println(response.readLine()); // //System.out.println(process.getInputStream().readLine()); // // String line, outputLine = ""; // // while((line = response.readLine()) != null) { // // outputLine += line; // // } // System.out.println("Op hai ye " + outputLine); process.waitFor (); // playSong ("StartBoy"); // print another message System.out.println("should be working...."); //response.close(); return getUrl (); } catch (Exception ex) { ex.printStackTrace(); } return "false"; }
public static void main(String[] args){ try { int generations; Scanner a = new Scanner(System.in); String currentDirectory; currentDirectory = System.getProperty("user.dir"); System.out.println("Current working directory : "+currentDirectory); Population pop = new Population(); String[] genArray = new String[16]; System.out.println("how many generations shall we listen to?"); generations = Integer.parseInt(a.next()); for(int i=1; i<=generations; i++){ createFolder("/Users/abraxas/Desktop/brainmusic/gen"+i); for(int m=0; m<16; m++){ genArray[m]=pop.getBna(m); } for(int n=0; n<16; n++){ String c = new String("./muse-player -l 5000 -C gen"+i+"/song"+(n+1)+" -i /muse/elements/delta_absolute /muse/elements/is_good"); Process read = Runtime.getRuntime().exec(c); MidiConverter.convertToMidi(genArray[n]); read.destroy(); System.out.println("Created data file gen"+i+"song"+(n+1)); CSVParse parser = new CSVParse("/Users/abraxas/Desktop/brainmusic/gen"+i+"/song"+(n+1)); double temp=parser.parse(); pop.setFitness(n,temp); } System.out.println("done gen"+i); pop = new Population(Selection.select(pop),pop); } System.out.println("all done!"); } catch(Exception e){ System.out.println(e.getMessage()); } }
private void populateViewer(){ if (db.DataBaseExists() == false) { JOptionPane.showMessageDialog(this, "The database file " + Configuration.DataBaseName() + " cannot be found!"); return; } double rows; mm = null; // View Selected Image Set Runtime.getRuntime().gc(); thumbnailViewer.removeAll(); String[] temp = new String[1]; if(this.mTaxaLevel.compareTo("Family") == 0){ temp[0] = listFamily.getSelectedItem(); } else if(this.mTaxaLevel.compareTo("Genus") == 0){ temp[0] = listFamily.getSelectedItem() + " " +listGenus.getSelectedItem(); } else if(this.mTaxaLevel.compareTo("Species") == 0) temp[0] = listFamily.getSelectedItem() + " " +listGenus.getSelectedItem() + " " + listSpecies.getSelectedItem(); else temp[0] = listFamily.getSelectedItem() + " " + listSpecies.getSelectedItem(); String[][] files = db.getFileNames(mTaxaLevel, temp, false, 0); String st; mm = new ImageIcon[files.length]; String[] mappedFileNames = new String[files.length]; jProgressBar1.setMaximum(files.length); jProgressBar1.setMinimum(0); mTotalinViewer = files.length; for(int i = 0; i < files.length; i++){ mappedFileNames[i] = files[i][0]; mm[i] = thumbnail.tempFunction(files[i][0]); jProgressBar1.setValue(i+1); jProgressBar1.update(jProgressBar1.getGraphics()); } mMappedFileNames = mappedFileNames; // Set the number of rows that can be displayed in the viewer rows = thumbnailViewer.getHeight() / 100; thumbnailViewer.setVisibleRowCount((int)rows); thumbnailViewer.setListData(mm); }
public DecodeManager(CConnection conn) { int cpuCount; this.conn = conn; threadException = null; decoders = new Decoder[Encodings.encodingMax+1]; queueMutex = new ReentrantLock(); producerCond = queueMutex.newCondition(); consumerCond = queueMutex.newCondition(); cpuCount = Runtime.getRuntime().availableProcessors(); if (cpuCount == 0) { vlog.error("Unable to determine the number of CPU cores on this system"); cpuCount = 1; } else { vlog.info("Detected "+cpuCount+" CPU core(s)"); // No point creating more threads than this, they'll just end up // wasting CPU fighting for locks if (cpuCount > 4) cpuCount = 4; // The overhead of threading is small, but not small enough to // ignore on single CPU systems if (cpuCount == 1) vlog.info("Decoding data on main thread"); else vlog.info("Creating "+cpuCount+" decoder thread(s)"); } freeBuffers = new ArrayDeque<MemOutStream>(cpuCount*2); workQueue = new ArrayDeque<QueueEntry>(cpuCount); threads = new ArrayList<DecodeThread>(cpuCount); while (cpuCount-- > 0) { // Twice as many possible entries in the queue as there // are worker threads to make sure they don't stall try { freeBuffers.addLast(new MemOutStream()); freeBuffers.addLast(new MemOutStream()); threads.add(new DecodeThread(this)); } catch (IllegalStateException e) { } } }
public int getSize() { return Runtime.getRuntime().availableProcessors() + 1; }
public static void processRegionFolder(File folder) { FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return file.getName().endsWith(".mca"); } }; ExecutorService threads = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); File[] files = folder.listFiles(); final int all = files.length; for (int i = 0; i < all; i++) { final File finalFile = files[i]; final int finalI = i; threads.execute(new Runnable() { @Override public void run() { int percent = finalI * 100 / all; processRegion(finalFile); System.out.println(" Progress: " + finalI + " / " + all + " (" + percent + "%)"); } }); } try { threads.awaitTermination(10, TimeUnit.DAYS); } catch (InterruptedException e) { e.printStackTrace(); } }
/** * Returns the default thread pool size, which is equivalent to the number of available processors minus 1, or 1 * - whichever is greater. * * @return the default pool size */ public static int defaultPoolSize() { return Math.max(1, Runtime.getRuntime().availableProcessors() - 1); }