本文整理匯總了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;
}
}
示例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();
}
示例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;
}
示例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)";
}
}
示例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)";
}
}
示例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();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
}
示例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)";
}
}