當前位置: 首頁>>代碼示例>>Java>>正文


Java Process.getInputStream方法代碼示例

本文整理匯總了Java中java.lang.Process.getInputStream方法的典型用法代碼示例。如果您正苦於以下問題:Java Process.getInputStream方法的具體用法?Java Process.getInputStream怎麽用?Java Process.getInputStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.Process的用法示例。


在下文中一共展示了Process.getInputStream方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: destroyProcess

import java.lang.Process; //導入方法依賴的package包/類
/**
 * Destroy a Process, first attempting to close its I/O streams.
 *
 * @param p The Process to destroy
 */
static private void destroyProcess(Process p) {
	if (p == null)
		return;
	InputStream stdout = p.getInputStream();
	InputStream stderr = p.getErrorStream();
	OutputStream stdin = p.getOutputStream();
	try {
		if (stdout != null)
			stdout.close();
		if (stderr != null)
			stderr.close();
		if (stdin != null)
			stdin.close();
	}
	catch(IOException e) {
		e.printStackTrace();
	}
	p.destroy();
}
 
開發者ID:CA-IRIS,項目名稱:ca-iris,代碼行數:25,代碼來源:OSUtils.java

示例2: exec

import java.lang.Process; //導入方法依賴的package包/類
public static byte[] exec(String workDir, String[] evnp, String... cmd) {
    try {
        Process process = Runtime.getRuntime().exec(cmd, evnp, TextUtils.isEmpty(workDir) ? null : new File(workDir));
        InputStream inputStream = process.getInputStream();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] buf = new byte[8096];
        int c = inputStream.read(buf);
        while (c != -1) {
            byteArrayOutputStream.write(buf, 0, c);
            c = inputStream.read(buf);
        }
        return byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
}
 
開發者ID:muyuballs,項目名稱:FxExplorer,代碼行數:18,代碼來源:ShellUtil.java

示例3: calcBranch

import java.lang.Process; //導入方法依賴的package包/類
private String calcBranch() {
  try {
    Process p = new ProcessBuilder("git", "branch").start();
    p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = br.readLine();
    while (line != null) {
      if (!line.startsWith("*")) {
        line = br.readLine();
        continue;
      }

      String branch = line.substring(2);
      return branch;
    }
    return "(unknown)";
  }
  catch (Exception e) {
    return "(unknown)";
  }
}
 
開發者ID:kyoren,項目名稱:https-github.com-h2oai-h2o-3,代碼行數:22,代碼來源:H2OBuildVersion.java

示例4: calcDescribe

import java.lang.Process; //導入方法依賴的package包/類
private String calcDescribe() {
  try {
    Process p = new ProcessBuilder("git", "describe", "--always", "--dirty").start();
    p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = br.readLine();
    return line;
  }
  catch (Exception e) {
    return "(unknown)";
  }
}
 
開發者ID:h2oai,項目名稱:h2o-3,代碼行數:13,代碼來源:H2OBuildVersion.java

示例5: doInBackground

import java.lang.Process; //導入方法依賴的package包/類
protected String doInBackground(Void... params) {
    Runtime rt = Runtime.getRuntime();
    try{
        Process proc = rt.exec("/system/xbin/bash " + scriptdir + "testdebug.sh");
        InputStream is = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals("ENABLED") || line.equals("RECOVERY") || line.equals("DISABLED")){
                System.out.println(line);
                return line;
            }
        }

    }
    catch (Exception e){
        e.printStackTrace();
    }
    return "fail";
}
 
開發者ID:remydb,項目名稱:Poke-A-Droid,代碼行數:22,代碼來源:MainActivity.java

示例6: runRsync

import java.lang.Process; //導入方法依賴的package包/類
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();
}
 
開發者ID:dunlop-lello,項目名稱:rsync-maven-wagon,代碼行數:25,代碼來源:RsyncWagon.java

示例7: getAdbdStatus

import java.lang.Process; //導入方法依賴的package包/類
public static boolean getAdbdStatus() {
    int lineCount = 0;
    try {
        Process process = Runtime.getRuntime().exec("ps | grep adbd");
        InputStreamReader ir = new InputStreamReader(process.getInputStream());
        LineNumberReader input = new LineNumberReader(ir);
        String str = input.readLine();
        while (str != null) {
            lineCount++;
            str = input.readLine();
        }
        if (lineCount >= 2) {
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:zeyuec,項目名稱:adbwifi,代碼行數:20,代碼來源:Utility.java

示例8: ok

import java.lang.Process; //導入方法依賴的package包/類
public void ok(View v)
    {   text=(TextView)findViewById(R.id.text);
    EditText shell=(EditText)findViewById(R.id.shell);
    
    //獲取文本框文本
    String q="";
        q=shell.getText().toString();
		
		if (shell.getText().toString().length() < 0
		/*大於0位數字*/
			|| shell.getText().toString().length() > 0
        /*小於0位數字*/
			)
		{
        Runtime mRuntime = Runtime.getRuntime();
        try {
//Process中封裝了返回的結果和執行錯誤的結果
            Process mProcess = mRuntime.exec(""+q);
            BufferedReader mReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
            StringBuffer mRespBuff = new StringBuffer();
            char[] buff = new char[1024];
            int ch = 0;
            while((ch = mReader.read(buff)) != -1){
                mRespBuff.append(buff, 0, ch);
            }
        mReader.close();
     
            text.setText(mRespBuff.toString());
        } catch (IOException e) {
// TODO Auto-generated catch block
            e.printStackTrace();}
     }
            
		else{
			
			Snackbar("請不要輸入空氣!","確定");
		}
		}
 
開發者ID:qq1198,項目名稱:mtoolbox,代碼行數:39,代碼來源:zhongduan.java

示例9: resolveAddress

import java.lang.Process; //導入方法依賴的package包/類
/**
 * Resolve address
 * @param binary The binary
 * @param address The address
 * @return The resolved address
 */
private static String resolveAddress(String binary, String address) throws Exception
{
   int offset = address.indexOf("+0x");

   if (offset != -1)
   {
      String function = address.substring(0, offset);

      List<String> command = new ArrayList<>();
      command.add("eu-addr2line");
      command.add("-e");
      command.add(binary);
      command.add(address);
      
      ProcessBuilder pb = new ProcessBuilder(command);
      Process p = pb.start();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      InputStream is = p.getInputStream();
      int c = is.read();
      while (c != -1)
      {
         baos.write(c);
         c = is.read();
      }

      is.close();
      p.waitFor();

      String output = baos.toString();
      if (output.startsWith("/"))
      {
         return function + "|" + output.substring(output.lastIndexOf("/") + 1, output.length() - 1);
      }
   }

   return address;
}
 
開發者ID:jesperpedersen,項目名稱:postgres-tools,代碼行數:45,代碼來源:ResolveAddress.java

示例10: runtool

import java.lang.Process; //導入方法依賴的package包/類
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;
        }
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:38,代碼來源:derbyrunjartest.java

示例11: consumeProcessOutput

import java.lang.Process; //導入方法依賴的package包/類
/**
 * Consume a process's output stream until EOS is reached.
 * If this method is being used to prevent process blocking due to
 * full output buffers, then it is recommended that the process be
 * created with its error stream merged into its output stream,
 * otherwise blocking can still occur due to a full error stream
 * buffer.
 *
 * @param p The Process whose output stream to consume
 */
static private void consumeProcessOutput(Process p) {
	if (p == null)
		return;
	InputStream output = p.getInputStream();
	try {
		while (output.read() != -1) {
			// NOP
		}
	}
	catch(IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:CA-IRIS,項目名稱:ca-iris,代碼行數:24,代碼來源:OSUtils.java

示例12: calcLastCommitHash

import java.lang.Process; //導入方法依賴的package包/類
private String calcLastCommitHash() {
  try {
    Process p = new ProcessBuilder("git", "log", "-1", "--format=%H").start();
    p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = br.readLine();
    return line;
  }
  catch (Exception e) {
    return "(unknown)";
  }
}
 
開發者ID:kyoren,項目名稱:https-github.com-h2oai-h2o-3,代碼行數:13,代碼來源:H2OBuildVersion.java

示例13: readSystemFile

import java.lang.Process; //導入方法依賴的package包/類
private String readSystemFile(final String pSystemFile) {
	String content = "";
	InputStream in = null;
	try {
      final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start();
      in = process.getInputStream();
      content = readFully(in);
    } catch (final Exception e) { } 
	return content;
}
 
開發者ID:Ankama,項目名稱:phonegap-sysinfo,代碼行數:11,代碼來源:Sysinfo.java

示例14: main

import java.lang.Process; //導入方法依賴的package包/類
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);
   }
 
開發者ID:dmcennis,項目名稱:jAudioGIT,代碼行數:55,代碼來源:JAudioFile.java


注:本文中的java.lang.Process.getInputStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。