java.lang.Runtime Java Examples
The following examples show how to use
java.lang.Runtime.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnvInfo.java From spring-rest with Apache License 2.0 | 6 votes |
final public static Map<String,String> mapEnvInfo(String filter) throws IOException { Process proc = Runtime.getRuntime().exec("env"); Map<String, String> ret = new HashMap<>(); try (InputStream stream = proc.getInputStream()) { try (Scanner s = new Scanner(stream).useDelimiter("\\n")) { while (s.hasNext()) { String val = s.next(); String[] nameVal = val.split("="); if (filter.equalsIgnoreCase("*")) ret.put(nameVal[0],nameVal.length > 1 ? nameVal[1] : ""); else { if (nameVal[0].startsWith(filter)) { ret.put(nameVal[0],nameVal.length > 1 ? nameVal[1] : ""); } } } } } return ret; }
Example #2
Source File: ProcessManager.java From jdk9-jigsaw with Creative Commons Zero v1.0 Universal | 6 votes |
public List<String> allProcesses() { List<String> processes = new LinkedList<String>(); try { String line; Process p = null; if(System.getProperty("os.name").toLowerCase().contains("win")) { p = Runtime.getRuntime().exec (System.getenv("windir") +"\\system32\\"+"tasklist.exe"); } else { p = Runtime.getRuntime().exec("ps -e"); } BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { processes.add(line); } input.close(); } catch (Exception err) { err.printStackTrace(); } return processes; }
Example #3
Source File: CubeSim.java From SoftwarePilot with MIT License | 5 votes |
void getPosition(String startPic){ System.out.println("##############"+startPic); try{ String cmd = "bash ../externalModels/python/3dPosition/run3d.sh "+startPic; Process p = Runtime.getRuntime().exec(cmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); x = Integer.parseInt(in.readLine().split("=")[1]); y = Integer.parseInt(in.readLine().split("=")[1]); z = Integer.parseInt(in.readLine().split("=")[1]); gimbal = Integer.parseInt(in.readLine().split("=")[1]); } catch(Exception e){ e.printStackTrace(); } if(x == 0) { Rmoves[0] = 0; Lmoves[0] = 1; } else { Lmoves[0] = 0; Rmoves[0] = 1; } if(z == 0) { Rmoves[2] = 0; Lmoves[2] = 1; } else { Lmoves[2] = 0; Rmoves[2] = 1; } if(y == 0) { Rmoves[1] = 0; Lmoves[1] = 2; } else if(y == 1) { Rmoves[1] = 1; Lmoves[1] = 1; } else { Rmoves[1] = 2; Lmoves[1] = 0; } }
Example #4
Source File: CubeSim.java From SoftwarePilot with MIT License | 5 votes |
public String driver_movt(String directory) { File CubeDir = new File(directory); File[] listOfFiles = CubeDir.listFiles(); int tx,ty,tz,tgimbal; for(File f : listOfFiles){ try { System.out.println(f.getName()); String cmd = "bash ../externalModels/python/3dPosition/run3d.sh "+directory+"/"+f.getName(); Process p = Runtime.getRuntime().exec(cmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); tx = Integer.parseInt(in.readLine().split("=")[1]); ty = Integer.parseInt(in.readLine().split("=")[1]); tz = Integer.parseInt(in.readLine().split("=")[1]); tgimbal = Integer.parseInt(in.readLine().split("=")[1]); System.out.println(x+" "+y+" "+z+" "+gimbal); System.out.println(tx+" "+ty+" "+tz+" "+tgimbal); if(x == tx && y == ty && z == tz && (gimbal == -tgimbal || gimbal == tgimbal)){ return directory + "/"+f.getName(); } } catch(Exception e){ e.printStackTrace(); } } System.out.println("Return Null"); return ""; }
Example #5
Source File: HostInfo.java From spring-rest with Apache License 2.0 | 5 votes |
public static String execReadToString(String execCommand) throws IOException { Process proc = Runtime.getRuntime().exec(execCommand); try (InputStream stream = proc.getInputStream()) { try (Scanner s = new Scanner(stream).useDelimiter("\\A")) { return s.hasNext() ? s.next() : ""; } } }
Example #6
Source File: derbyrunjartest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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; } } }
Example #7
Source File: derbyrunjartest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
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; } } }
Example #8
Source File: RNDeviceModule.java From react-native-device-info with MIT License | 4 votes |
@ReactMethod(isBlockingSynchronousMethod = true) public int getUsedMemorySync() { Runtime rt = Runtime.getRuntime(); long usedMemory = rt.totalMemory() - rt.freeMemory(); return (int)usedMemory; }
Example #9
Source File: RNDeviceModule.java From react-native-device-info with MIT License | 4 votes |
@ReactMethod(isBlockingSynchronousMethod = true) public double getMaxMemorySync() { return (double)Runtime.getRuntime().maxMemory(); }