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


Java Process.waitFor方法代碼示例

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


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

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

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

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

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

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

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

import java.lang.Process; //導入方法依賴的package包/類
@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;
}
 
開發者ID:AmauryOrtega,項目名稱:Sem-Update,代碼行數:22,代碼來源:ServidorControlador.java

示例8: runClientSide

import java.lang.Process; //導入方法依賴的package包/類
/**
 * Runs MXBeanWeirdParamTest$ClientSide with the passed options and redirects
 * subprocess standard I/O to the current (parent) process. This provides a
 * trace of what happens in the subprocess while it is runnning (and before
 * it terminates).
 *
 * @param serviceUrlStr string representing the JMX service Url to connect to.
 */
private int runClientSide(String serviceUrlStr) throws Exception {

    // Building command-line
    List<String> opts = buildCommandLine();
    opts.add(serviceUrlStr);

    // Launch separate JVM subprocess
    int exitCode = 0;
    String[] optsArray = opts.toArray(new String[0]);
    ProcessBuilder pb = new ProcessBuilder(optsArray);
    Process p = ProcessTools.startProcess("MXBeanWeirdParamTest$ClientSide", pb);

    // Handling end of subprocess
    try {
        exitCode = p.waitFor();
        if (exitCode != 0) {
            System.out.println(
                "Subprocess unexpected exit value of [" + exitCode +
                "]. Expected 0.\n");
        }
    } catch (InterruptedException e) {
        System.out.println("Parent process interrupted with exception : \n " + e + " :" );

        // Parent thread unknown state, killing subprocess.
        p.destroyForcibly();

        throw new RuntimeException(
            "Parent process interrupted with exception : \n " + e + " :" );
    } finally {
        return exitCode;
    }

 }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:42,代碼來源:MXBeanWeirdParamTest.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: 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


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