java.lang.Process#getInputStream ( )源码实例Demo

下面列出了java.lang.Process#getInputStream ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ShareBox   文件: WifiUtil.java
public static ArrayList<String> nativeGetConnectedIP(String deviceName) {
        ArrayList<String> connectedIP = new ArrayList<String>();
        try {
            Process local=Runtime.getRuntime().exec("cat /proc/net/arp");

            DataInputStream os=new DataInputStream(local.getInputStream());

            String line;
            Log.i(TAG,"arp begin");
            while ((line = os.readLine()) != null) {
                Log.i(TAG, line);
                String[] splited = line.split("\\s+");
                if (splited != null && splited.length > 5) {
                    if(!splited[3].equals("00:00:00:00:00:00")&&splited[5].contains(deviceName)){
                        String ip = splited[0];
                        connectedIP.add(ip);
                    }
                }
            }
            Log.i(TAG,"arp end");
        } catch (IOException e) {
            e.printStackTrace();
        }
//        connectedIP.remove(0);
        return connectedIP;
    }
 
源代码2 项目: spring-rest   文件: EnvInfo.java
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;
  }
 
源代码3 项目: jdk9-jigsaw   文件: ProcessManager.java
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;
}
 
源代码4 项目: spring-rest   文件: HostInfo.java
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() : "";
        }
    }
}
 
源代码5 项目: dacapobench   文件: DaCapoClientRunner.java
public static void runIteration(String size, int numThreads, boolean useBeans) {

    try {

      /* Calling the function directly does not launch the client now. According to testing, it seems the getMain method of boot does not work properlly.
         Thus these ugly codes are temporarily used for checking the whole framework
         Will be changed once the problem is fixed
      */
      //ClientCLI.main(new String[] { car, "-i", "-t", numThreads + "", "-s", size, useBeans ? "-b" : "" });

      String jhome= System.getProperty("java.home");

      ProcessBuilder pb = new ProcessBuilder(jhome + "/bin/java", "-jar", "-Dkaraf.startLocalConsole=false", gero + "/bin/client.jar", car, "-t", numThreads + "", "-s", size, useBeans ? "-b" : "");
      Process p = pb.start();
      p.waitFor();

      BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
      while (stdInput.ready()) { //While there's something in the buffer
        //read&print - replace with a buffered read (into an array) if the output doesn't contain CR/LF
        System.out.println(stdInput.readLine());
      }

    } catch (Exception e) {
      System.err.print("Exception running client iteration: " + e.toString());
      e.printStackTrace();
    }
  }
 
源代码6 项目: gemfirexd-oss   文件: derbyrunjartest.java
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;
        }
    }
}
 
源代码7 项目: gemfirexd-oss   文件: derbyrunjartest.java
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;
        }
    }
}
 
源代码8 项目: repairnator   文件: RepairnatorPostBuild.java
public void printProcessOutPut(Process process) throws IOException{
    try (BufferedReader reader = new BufferedReader(
        new InputStreamReader(process.getInputStream()))) {
        reader.lines().forEach(line -> System.out.println(line));
    }
}
 
源代码9 项目: jAudioGIT   文件: JAudioFile.java
public static void main(String[] args) throws Exception{
   	processor = new AudioStreamProcessor(args[0],args[1]);

String base_prefix =args[2];
base_prefix += args[4];

ProcessBuilder gstreamerBuilder = new ProcessBuilder("gst-launch-1.0", "-q", "filesrc", "location="+args[3], "!", "decodebin", "!", "audioconvert", "!", "audio/x-raw,format=F32LE", "!", "fdsink");
Process gstreamer =  gstreamerBuilder.start();
       DataInputStream input = new DataInputStream(gstreamer.getInputStream());
ByteBuffer buffer = ByteBuffer.allocateDirect(1000000000);
buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);
       byte[] b = new byte[1000000];
int read=0;
int total=0;
while((read = input.read(b))>-1){
	total += read;
	if(read > 0)
		buffer.put(b,0,read);
}
System.out.println();
buffer.flip();
FloatBuffer db = buffer.asFloatBuffer();

       double[] samples = new double[total / 8];
for(int i=0;i<samples.length;++i){
	samples[i] = (db.get()+db.get()) / 2.0;
}	
db = null;
       buffer = null;
double max=0.0;
double min=0.0;
boolean okay = false;
if(samples.length < 512){
	throw new Exception("File is too small to analyze - "+samples.length+" samples");
}
for(int i=0;i<samples.length;++i){
		if((samples[i] > 1.0) || (samples[i] < -1.0)){
		throw new Exception("Badly formatted data "+i+" "+samples[i]);
	}
	if((samples[i] > 0.7)){
		okay = true;
	}
}
if(!okay){
	throw new Exception("Data is artificially small - probable endianess problem");
}
processor.process(samples);

Date date = new Date();
       String attach = date.toString();
       attach = Pattern.compile("\\s").matcher(attach).replaceAll("_");
       base_prefix += Pattern.compile(":").matcher(attach).replaceAll("-");
       processor.output(base_prefix);
   }