- 浏览: 857979 次
- 性别:
- 来自: 上海
最新评论
-
waterflow:
感谢分享
简单的ChartDirector生成图表例子 -
YQuite:
写到最后一种文件才看到这个,洼的一声哭了出来 - - !
java简单解析docx、pptx、xlsx文档 -
q394469902:
Android通过selector改变界面状态 -
db6623919:
直接粘贴别人帖子还是英文的,有意思?
实现RTSP协议的简单例子 -
ykou314:
请问下,这些超级命令,是否需要android root权限,尤 ...
Android系统在超级终端下必会的命令大全(七)
/**
* ShellCommand.java runs commands as if in a native shell instance, and can return stdio.
*
* Code by Kevin(at)TeslaCoil
* Adapted by LouZiffer(at)SDX
*
* Example usage (use cmd.su.runWaitFor instead of cmd.sh.runWaitFor to run as su):
*
* ShellCommand cmd = new ShellCommand();
* CommandResult r = cmd.sh.runWaitFor("/system/bin/getprop wifi.interface");
*
* if (!r.success()) {
* Log.d(MSG_TAG, "Error " + r.stderr);
* } else {
* Log.d(MSG_TAG, "Successfully executed getprop wifi.interface. Result: " + r.stdout);
* this.tetherNetworkDevice = (r.stdout);
* }
*/
package m900.tether.system;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import android.util.Log;
public class ShellCommand {
private static final String TAG = "ShellCommand.java";
private Boolean can_su;
public SH sh;
public SH su;
public ShellCommand() {
sh = new SH("sh");
su = new SH("su");
}
public boolean canSU() {
return canSU(false);
}
public boolean canSU(boolean force_check) {
if (can_su == null || force_check) {
CommandResult r = su.runWaitFor("id");
StringBuilder out = new StringBuilder();
if (r.stdout != null)
out.append(r.stdout).append(" ; ");
if (r.stderr != null)
out.append(r.stderr);
Log.v(TAG, "canSU() su[" + r.exit_value + "]: " + out);
can_su = r.success();
}
return can_su;
}
public SH suOrSH() {
return canSU() ? su : sh;
}
public class CommandResult {
public final String stdout;
public final String stderr;
public final Integer exit_value;
CommandResult(Integer exit_value_in, String stdout_in, String stderr_in)
{
exit_value = exit_value_in;
stdout = stdout_in;
stderr = stderr_in;
}
CommandResult(Integer exit_value_in) {
this(exit_value_in, null, null);
}
public boolean success() {
return exit_value != null && exit_value == 0;
}
}
public class SH {
private String SHELL = "sh";
public SH(String SHELL_in) {
SHELL = SHELL_in;
}
public Process run(String s) {
Process process = null;
try {
process = Runtime.getRuntime().exec(SHELL);
DataOutputStream toProcess = new DataOutputStream(process.getOutputStream());
toProcess.writeBytes("exec " + s + "\n");
toProcess.flush();
} catch(Exception e) {
Log.e(TAG, "Exception while trying to run: '" + s + "' " + e.getMessage());
process = null;
}
return process;
}
private String getStreamLines(InputStream is) {
String out = null;
StringBuffer buffer = null;
DataInputStream dis = new DataInputStream(is);
try {
if (dis.available() > 0) {
buffer = new StringBuffer(dis.readLine());
while(dis.available() > 0)
buffer.append("\n").append(dis.readLine());
}
dis.close();
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
if (buffer != null)
out = buffer.toString();
return out;
}
public CommandResult runWaitFor(String s) {
Process process = run(s);
Integer exit_value = null;
String stdout = null;
String stderr = null;
if (process != null) {
try {
exit_value = process.waitFor();
stdout = getStreamLines(process.getInputStream());
stderr = getStreamLines(process.getErrorStream());
} catch(InterruptedException e) {
Log.e(TAG, "runWaitFor " + e.toString());
} catch(NullPointerException e) {
Log.e(TAG, "runWaitFor " + e.toString());
}
}
return new CommandResult(exit_value, stdout, stderr);
}
}
}
发表评论
-
One省电卫士 - Android内核级省电App
2013-02-03 19:32 3505One省电卫士是一款androi ... -
(转)Windows下Eclipse集成Cygwin配置Android NDK环境编译JNI库程序步骤
2012-05-09 16:11 5546前戏准备: 1. 搭建Eclipse Android ... -
Android-Task和Activity相关的一些属性[转]
2011-08-23 09:21 2990android:allowTaskReparenting用来标 ... -
GC_FOR_MALLOC
2011-07-01 11:44 2245GC_FOR_MALLOC means that the ... -
ProgressBar 样式
2011-05-01 23:06 3105The four attributes that you me ... -
Android任务管理终极发布AndTask 3.1(安安任务管理)
2011-04-04 07:50 1608安安任务管理是一款android任务管理软件,可通过手动或自动 ... -
AndMemory 安安内存管理 1.1 发布
2011-03-08 23:42 1845AndMemory is an android memory ... -
预测今年将是android应用普及年和android安全年
2011-03-06 21:53 1902经过去年一年的实践,预测今年将是android应用 ... -
Android之混淆(Obfuscate)
2011-03-06 16:07 2833下载Android安安软件请到:http://code. ... -
Android内存信息
2011-02-21 21:40 2118下载Android安安软件请到:http://code.goo ... -
How to decompile .dex file on Android(转)如何反编译.dex文件
2011-02-20 11:34 2815下载Android安安软件请到:http://code.goo ... -
(转)android JNI 学习笔记1
2011-02-17 10:08 2744下载Android安安软件请到:http://code.goo ... -
(转)Android内存管理机制之一:lowmemory killer
2011-02-15 15:00 2579下载Android安安软件请到 ... -
(转)内存管理Memory Management in Android
2011-02-14 23:31 4128下载Android安安软件请到:http://code.goo ... -
转-Andriod被排出Linux内核的原因
2011-01-12 22:36 1477下载Android安安软件请到:http://code.goo ... -
Ubuntu 开启 Android 的 USB 调试模式
2011-01-06 20:51 7703在Android开发者网站中, 它提供了在 Ubuntu 下实 ... -
解决Conversion to Dalvik format failed: Unable to execute dex: null
2010-12-12 23:17 2347解决Conversion to Dalvik format f ... -
AndBox发布最新版AndRootFile(安安文件管理) 3.0 beta 版
2010-11-27 09:56 1718The ultimate file manager for r ... -
(转)区分Activity的四种加载模式
2010-11-20 10:09 1727在多Activity开发中,有可能是自己应用之间的Activi ... -
(转)Android实现日历
2010-11-09 17:12 2582下载Android安安软件请到:http://code.goo ...
相关推荐
at org.apache.hadoop.util.Shell.runCommand(Shell.java:538) at org.apache.hadoop.util.Shell.run(Shell.java:455).... 这是hadoop本身的一个bug,可以通过修改NativeIO和YARNRunner的源码并替换解决。这是这两个...
at org.apache.hadoop.util.Shell.runCommand(Shell.java:482) at org.apache.hadoop.util.Shell.run(Shell.java:455) at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:715) at ...
在Unix Shell脚本里运行Java application
It is handled by Jad rather than the command shell, so on UNIX the last argument should be single-quoted: jad -o -r -sjava -dsrc 'tree/**/*.class' In a case you want to check the accuracy of the ...
##AdbShellCommand在Android项目中执行adb Shell命令,通过java代码调用执行,本程序采用MVP架构。###Java中执行adb shell命令本项目中,adb shell命令执行的实现方法主要参考网文()。文章中,把执行代码集成在...
at org.apache.hadoop.util.Shell.runCommand(Shell.java:482) 2:window10操作系统下面。hadoop-2.6.4版本,解决上面这个问题的必须两个文件。详细见博客:http://www.cnblogs.com/biehongli/p/7895857.html 3:...
在java代码中调用执行shell脚本,sqlldr导数与使用sqlplus在shell调用执行存储过程。 linux环境中有2个dba的用户:oracle、erm 还有1个web用户:erm 在linux环境中,这三个用户都可以直接在任意目录下执行该shell...
But Python is just as powerful as Java. If Java is the heavy metal of computer programming, then Python is the jazz that opens doors of freedom in software development. Both Java and Python are ...
Table of Content Table of Content.........................................................................................................................i Copyright....................................
2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 6 6 6 6 6 7 7 7 8 11 11 13 15 15 16 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . ...
It is handled by Jad rather then command shell, so on UNIX the last argument should be single-quoted: jad -o -r -sjava -dsrc 'tree/**/*.class' In case you want to check the accuracy of the ...
6 Using the Command-Line Tools and the Android Emulator . . . . . . . . . . . . 83 Creating a Shell Activity Using the Windows CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Running ...
shell - start shell command ex:!shell sh test.sh 1116.!export - export a file ,if filepath have block,use '^' instead,ex:!export e:\test\test.txt isappend(true/false) datas7.!file - return a file ...
any shell command ... ( sh/uname -a) ; ;returns a # ; ; using clojure variables (vars, local bindings) in shake ( let [home " /home/sunng87 " ] ( sh/ls -l $home)) ; ; using clojure forms in shake ( ...
Packages ...com.kingdee.bos.framework.command ...com.kingdee.bos.util.backport.concurrent.helpers Auxiliary and helper classes for backport.util.concurrent, NOT present in java.util.concurrent. ...
static HttpResponse httpGet(java.lang.String httpUrl) static String httpGetString(String httpUrl) 包含以上三个方法,默认使用gzip压缩,使用bufferedReader提高读取速度。 HttpRequest中可以设置url、timeout...
PART I – 概览.........................................................................................................................11 第 1章 – DB2 Express-C是什么?..................................
1.找到HKEY_CLASSES_ROOT\http\shell\open\command,双击"默认",将要用浏览器的可执行文件的完全路径输入到这里,例如:输入“C:\Program Files\Internet Explorer\iexplore.exe”; 2.然后找到HKEY_CLASSES_ROOT\...
It is handled by Jad rather than the command shell, so on UNIX the last argument should be single-quoted: <br> jad -o -r -sjava -dsrc 'tree/**/*.class' <br> In a case you want to check ...
5) 在注册表编辑器中,找到"HKEY_CLASSES_ROOT\Applications\javaw.exe\shell\open\command",在其中⽂件打开命令中加 ⼊参数"-jar"(⽆引号),修改后的数值类似:""C:\ProgramFiles\Java\jre7\bin\javaw.exe" -jar ...