如何可以运行在Android的Linux命令 [英] how can run Linux command on android

查看:99
本文介绍了如何可以运行在Android的Linux命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些Android设备,我只可以运行回声,CD,LS......这样的Linux命令在亚行的shell,但是当我运行

On some Android device, I only can run "echo", "cd", "ls"... this kind of Linux command in adb shell, but when I run

tar -cvf //mnt/sdcard/BackUp1669/apk/test.tar /mnt/sdcard/test.apk

(或称CP等),则返回:

(or "cp" etc.) it returns:

sh: tar: not found

为什么呢?而且是无法在Android上运行的Linux命令。

Why? And is it impossible to run Linux command on Android.

PS。一些设备支持上面的命令。

ps. some device support the above command.

非常感谢。

其实,我要从中复制/数据/数据​​文件夹中的文件到SD卡,我得到了苏和用

Actually, I want to copy a file from /data/data folder to sdcard, I got su and use

    int timeout = 1000;
    String command = "tar -cvf /" + Environment.getExternalStorageDirectory() + "/cp/"
            + packageName + ".tar" + " " + path;
    DataOutputStream os = new DataOutputStream(process.getOutputStream());
    BufferedReader is = new BufferedReader(new InputStreamReader(new DataInputStream(
            process.getInputStream())), 64);

    String inLine;
    try {
        StringBuilder sbCommand = new StringBuilder();
        sbCommand.append(command).append(" ");
        sbCommand.append("\n");
        os.writeBytes(command.toString());
        if (is != null) {
            for (int i = 0; i < timeout; i++) {
                if (is.ready())
                    break;
                try {
                    Thread.sleep(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (is.ready()) {
                inLine = is.readLine();
            } else {
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

它总是在块is.ready(),我把它改为process.waitfor();这也阻止了。为什么呢?

It always blocks in "is.ready()", and I changed it to process.waitfor(); it also blocks, too. Why?

推荐答案

您可以运行在Android Linux命令。但也有通常只是极少数pre-安装。 如果你想添加更多的命令,你可能要您的设备和安装的就可以了busybox的

You can run Linux commands on Android. But there are usually just very few pre-installed. If you want to add more commands you might want to root your device and install busybox on it.

这是不是用于生产用途的应用程序中,但可以帮助您与您的设备一起工作。

This is not for productive use within an application but can help you to work with your device.

这篇关于如何可以运行在Android的Linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆