关于android 调用外部命令的问题(Runtime.getRuntime().exec参数)

android 调用外部命令的问题(Runtime.getRuntime().exec参数)
调用ls还有cat命名是没问题的,但是有些命令用不了,例如ll,打印显示环境有问题,不知道怎么解?

代码:
private String ssss() {
String TAG2 = "CMD";
try {

    String  cmd="ls";
    Process process =Runtime.getRuntime().exec(cmd);
    InputStream in1 = process.getInputStream();
    BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
    String line1;
    Log.i(TAG2, "返回结果" + reader1.readLine());
    while ((line1 = reader1.readLine()) != null) {

        Log.i(TAG2, "返回结果=" + line1);
    }
    in1.close();
} catch (IOException ex) {
    ex.printStackTrace();
    //  result2 = "N/A";
}
return null;

}

String cmd="ls"打印结果:
644-644/com.example.MEM I/CMD﹕ 返回结果acct
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=config
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=d
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=default.prop
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=etc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.goldfish.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.recovery.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdb.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sdd.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.sun7i.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=init.trace.rc
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=initlogo.rle
03-23 16:42:56.157 644-644/com.example.MEM I/CMD﹕ 返回结果=nand.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=proc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sbin
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=sun7i-ir.ko
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=system
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.goldfish.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=ueventd.sun7i.rc
03-23 16:42:56.167 644-644/com.example.MEM I/CMD﹕ 返回结果=null

String cmd="ll"打印结果:
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ java.io.IOException: Error running exec(). Command: [ll] Working Directory: null Environment: null
03-23 16:46:52.337 3166-3166/com.example.MEM W/System.err﹕ at java.lang.ProcessManager.exec(ProcessManager.java:211)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:168)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:241)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at java.lang.Runtime.exec(Runtime.java:184)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss(MyActivity.java:464)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
03-23 16:46:52.347 3166-3166/com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)

android 里面没有ll这个命令,用ls -l

和权限有关系吧 就像windows 需要管理员权限一样

我装了一个ethtool工具(装在/system/bin下) $ethtool eth0 可以查看以太网信息

写了个apk,调用这个命令,然后返回打印信息

用2不同的Cubieboard开发板 一个能用 一个不能用,,,但是直接在板子上adb shell(执行ethtool eth0) 是可以用的

下面是打印信息:

ct:
com.example.MEM I/IR﹕ thread usb1 start
com.example.MEM I/IR﹕ thread usb1 start 500ms
com.example.MEM I/IR﹕ dd start
com.example.MEM W/System.err﹕ java.io.SyncFailedException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:77)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.flush(FileOutputStream.java:194)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.flush(DataOutputStream.java:63)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:541)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4206)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:7792)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5473)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2683)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7207)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3719)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3669)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2835)
com.example.MEM W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5041)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:582)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at libcore.io.Posix.fsync(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:97)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:74)
com.example.MEM W/System.err﹕ ... 30 more
com.example.MEM W/System.err﹕ java.io.SyncFailedException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:77)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.flush(FileOutputStream.java:194)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.flush(FilterOutputStream.java:88)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.flush(DataOutputStream.java:63)
com.example.MEM W/System.err﹕ at java.io.FilterOutputStream.close(FilterOutputStream.java:61)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:542)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4206)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:7792)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5473)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2683)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7207)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3719)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3669)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2835)
com.example.MEM W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5041)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:582)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: fsync failed: EINVAL (Invalid argument)
com.example.MEM W/System.err﹕ at libcore.io.Posix.fsync(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:97)
com.example.MEM W/System.err﹕ at java.io.FileDescriptor.sync(FileDescriptor.java:74)
com.example.MEM W/System.err﹕ ... 31 more
com.example.MEM I/IR﹕ ---------------------------Thread start

com.example.MEM I/IR﹕ ddddddddddddddddddddddddddddddddddddddddddddd= Settings for eth0:

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported ports: [ TP AUI BNC MII FIBRE ]

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported link modes: 10baseT/Half 10baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 100baseT/Half 100baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 1000baseT/Half 1000baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Supported pause frame use: No

com.example.MEM I/IR﹕ oooooooooooooooooo= Supports auto-negotiation: Yes

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised link modes: 10baseT/Half 10baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 100baseT/Half 100baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= 1000baseT/Half 1000baseT/Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised pause frame use: No

com.example.MEM I/IR﹕ oooooooooooooooooo= Advertised auto-negotiation: Yes

com.example.MEM I/IR﹕ oooooooooooooooooo= Speed: 1000Mb/s

com.example.MEM I/IR﹕ oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooookkkkkkkkkkkk1

com.example.MEM I/IR﹕ oooooooooooooooooo= Duplex: Full

com.example.MEM I/IR﹕ oooooooooooooooooo= Port: MII

com.example.MEM I/IR﹕ oooooooooooooooooo= PHYAD: 0

com.example.MEM I/IR﹕ oooooooooooooooooo= Transceiver: external

com.example.MEM I/IR﹕ oooooooooooooooooo= Auto-negotiation: on

com.example.MEM I/IR﹕ oooooooooooooooooo= Current message level: 0x0000003f (63)

com.example.MEM I/IR﹕ oooooooooooooooooo= drv probe link timer ifdown ifup

com.example.MEM I/IR﹕ oooooooooooooooooo= Link detected: yes

这个有报错 但是可以返回打印信息

ct plus:
com.example.MEM I/IR﹕ thread usb1 start
com.example.MEM I/IR﹕ thread usb1 start 500ms
com.example.MEM W/System.err﹕ java.io.IOException: write failed: EPIPE (Broken pipe)
com.example.MEM W/System.err﹕ at libcore.io.IoBridge.write(IoBridge.java:455)
com.example.MEM W/System.err﹕ at java.io.FileOutputStream.write(FileOutputStream.java:202)
com.example.MEM W/System.err﹕ at java.io.OutputStream.write(OutputStream.java:82)
com.example.MEM W/System.err﹕ at java.io.DataOutputStream.writeBytes(DataOutputStream.java:156)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.ssss1(MyActivity.java:536)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity.access$000(MyActivity.java:32)
com.example.MEM W/System.err﹕ at com.example.MEM.MyActivity$1.onClick(MyActivity.java:90)
com.example.MEM W/System.err﹕ at android.view.View.performClick(View.java:4438)
com.example.MEM W/System.err﹕ at android.view.View.onKeyUp(View.java:8241)
com.example.MEM W/System.err﹕ at android.widget.TextView.onKeyUp(TextView.java:5628)
com.example.MEM W/System.err﹕ at android.view.KeyEvent.dispatch(KeyEvent.java:2723)
com.example.MEM W/System.err﹕ at android.view.View.dispatchKeyEvent(View.java:7665)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
com.example.MEM W/System.err﹕ at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
com.example.MEM W/System.err﹕ at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3873)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3847)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3544)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3445)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3601)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3445)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3418)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3468)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3437)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3577)
com.example.MEM W/System.err﹕ at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3737)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
com.example.MEM W/System.err﹕ at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
com.example.MEM W/System.err﹕ at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
com.example.MEM W/System.err﹕ at android.os.MessageQueue.nativePollOnce(Native Method)
com.example.MEM W/System.err﹕ at android.os.MessageQueue.next(MessageQueue.java:138)
com.example.MEM W/System.err﹕ at android.os.Looper.loop(Looper.java:123)
com.example.MEM W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5017)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
com.example.MEM W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
com.example.MEM W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
com.example.MEM W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
com.example.MEM W/System.err﹕ Caused by: libcore.io.ErrnoException: write failed: EPIPE (Broken pipe)
com.example.MEM W/System.err﹕ at libcore.io.Posix.writeBytes(Native Method)
com.example.MEM W/System.err﹕ at libcore.io.Posix.write(Posix.java:202)
com.example.MEM W/System.err﹕ at libcore.io.BlockGuardOs.write(BlockGuardOs.java:197)
com.example.MEM W/System.err﹕ at libcore.io.IoBridge.write(IoBridge.java:450)
com.example.MEM W/System.err﹕ ... 50 more
这个报错,没有返回我要的打印信息