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


Java Process類代碼示例

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


Process類屬於java.lang包,在下文中一共展示了Process類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: setAdbWifiStatus

import java.lang.Process; //導入依賴的package包/類
public static boolean setAdbWifiStatus(boolean status) {
    Process p;
    try {
        p = Runtime.getRuntime().exec("su"); 

        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        os.writeBytes("setprop service.adb.tcp.port " + String.valueOf(getPort()) + "\n");
        os.writeBytes("stop adbd\n");
        
        if (status) {
            os.writeBytes("start adbd\n");
        }
        os.writeBytes("exit\n");
        os.flush();
            
        p.waitFor();
        if (p.exitValue() != 255) {
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:zeyuec,項目名稱:adbwifi,代碼行數:27,代碼來源:Utility.java

示例3: spawnProcess

import java.lang.Process; //導入依賴的package包/類
/**
 * Spawn an OS subprocess.  Follows the Oracle-recommended method of
 * using ProcessBuilder rather than Runtime.exec(), and includes some
 * safeguards to prevent blocked and stale processes.  A thread is
 * created that will perform the spawn, consume its output and error
 * streams (to prevent blocking due to full buffers), then clean up.
 *
 * @param cmd The cmd/arg list for execution
 */
static public void spawnProcess(final List<String> cmd) {
	if (cmd == null)
		return;
	Thread t = new Thread() {
		public void run() {
			Process proc = null;
			proc = startProcess(cmd, true);
			if (proc != null) {
				consumeProcessOutput(proc);
				try {
					proc.waitFor();
				}
				catch (InterruptedException e) {
					// ignore (we terminate anyway)
				}
				destroyProcess(proc);
			}
			Thread.currentThread().interrupt();
		}
	};
	t.setDaemon(true);
	t.start();
}
 
開發者ID:CA-IRIS,項目名稱:ca-iris,代碼行數:33,代碼來源:OSUtils.java

示例4: startProcess

import java.lang.Process; //導入依賴的package包/類
/**
 * Start a new process.
 *
 * @param cmd The cmd/arg list for execution
 * @param merge True to merge the process's error stream into its
 *              output stream
 * @return The new Process, or null upon failure
 */
static private Process startProcess(List<String> cmd, boolean merge) {
	if (cmd == null)
		return null;
	ProcessBuilder pb = new ProcessBuilder(cmd);
	if (merge)
		pb = pb.redirectErrorStream(true);
	Process proc = null;
	try {
		proc = pb.start();
	}
	catch(IOException e) {
		e.printStackTrace();
	}
	return proc;
}
 
開發者ID:CA-IRIS,項目名稱:ca-iris,代碼行數:24,代碼來源:OSUtils.java

示例5: installrootfs_priv

import java.lang.Process; //導入依賴的package包/類
private boolean installrootfs_priv(String from, String target)
{
	try
	{
		Runtime runtime = Runtime.getRuntime();
		String[] envp = {"BUSYBOX=/data/data/org.Ex3.AndLinux/files/utils/busybox",
			"SRC=" + from,
			"TGT=" + target};
			int ret;
		Process process = runtime.exec("/data/data/org.Ex3.AndLinux/files/utils/install.sh", envp);
		if ((ret = process.waitFor()) != 0)
		{
			Log.d("install", String.valueOf(ret));
			ToastUtils.showText(this, getString(R.string.error), Toast.LENGTH_LONG);
			return false;
		}
	}
	catch (Throwable ob)
	{
		ob.printStackTrace();
		ToastUtils.showText(this, ob.getMessage(), Toast.LENGTH_LONG);
		return false;
	}
	ToastUtils.showText(this, getString(R.string.success), Toast.LENGTH_LONG);
	return true;
}
 
開發者ID:MG-MaGeek,項目名稱:AndLinux,代碼行數:27,代碼來源:App.java

示例6: create

import java.lang.Process; //導入依賴的package包/類
@VisibleForTesting
static FileDescriptorFactory create(String address, String... cmd) throws IOException {
    // must be created before the process
    final LocalServerSocket socket = new LocalServerSocket(address);
    try {
        final Process shell = new ProcessBuilder(cmd)
                .redirectErrorStream(true)
                .start();

        final FileDescriptorFactory result = new FileDescriptorFactory(shell, socket);

        result.startServer();

        return result;
    } catch (Throwable t) {
        shut(socket);

        throw t;
    }
}
 
開發者ID:chdir,項目名稱:fdshare,代碼行數:21,代碼來源:FileDescriptorFactory.java

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: generatePolicyToken

import java.lang.Process; //導入依賴的package包/類
public void generatePolicyToken(String presentationPolicyDest) {

    StringWriter sw = new StringWriter();
    sw.write(this.serialPolicy);
 
    try {

     FileWriter fw = new FileWriter(presentationPolicyDest);
     fw.write(sw.toString());
     fw.close();

     Process pr = Runtime.getRuntime().exec(this.generationScript, null, new File(this.generationScriptPath));

    } catch (Exception e) {
     e.printStackTrace();
    }
  }
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:18,代碼來源:TokenGenerator.java

示例12: 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

示例13: 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

示例14: 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

示例15: clearRecording

import java.lang.Process; //導入依賴的package包/類
public void clearRecording() {
  log.info("USER {}: END recording in room {}", name, roomName);
  recorderCaller.stop();
  recorderCaller.release();
  // conversion
  log.info("should run {}", pendingConversion);
  if (pendingConversion == true) {
    log.info("Run Conversion");
    new Thread(new Runnable() {
      public void run(){
         try {
          log.info("Running: {}", "ffmpeg -i " + RECORDING_PATH + preConvertedName + RECORDING_EXT + " -strict -2 -q:vscale 0 " + RECORDING_PATH + preConvertedName + ".mp4");
          Process proc = Runtime.getRuntime().exec("ffmpeg -i " + RECORDING_PATH + preConvertedName + RECORDING_EXT + " -strict -2 -q:vscale 0 " + RECORDING_PATH + preConvertedName + ".mp4");
          proc.waitFor();
          log.info("Running: {}", "ffmpeg -i " + RECORDING_PATH + preConvertedName + ".mp4 -profile:v baseline -level 3.0 -s 1280x960 -start_number 0 -hls_time 10 -hls_list_size 0 -strict -2 -f hls " + RECORDING_PATH + preConvertedName +".m3u8");
          Runtime.getRuntime().exec("ffmpeg -i " + RECORDING_PATH + preConvertedName + ".mp4 -profile:v baseline -level 3.0 -s 1280x960 -start_number 0 -hls_time 10 -hls_list_size 0 -strict -2 -f hls " + RECORDING_PATH + preConvertedName +".m3u8");
        }
        catch (IOException e) {
          log.info(e.getMessage());
        }
        catch (InterruptedException ie) {
          log.info(ie.getMessage());
        }
      }
    }).start();
  }
  pendingConversion = false;
}
 
開發者ID:jake-kent,項目名稱:TLIVideoConferencingv2,代碼行數:29,代碼來源:UserSession.java


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