简体   繁体   English

在Android应用中运行linux命令并读取输出

[英]Running linux command in Android app and reading output

How can I run a linux command from an Android App and read the output. 如何从Android App运行linux命令并读取输出。 For example: retrieving output of "ls -lh" and printing as a text in TextView? 例如:检索“ ls -lh”的输出并在TextView中打印为文本?

Try this: 尝试这个:

try{
                Process process;            
                process = Runtime.getRuntime().exec("ls -lh");
                BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        }
        catch (InterruptedException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }

After this in post to your TextView. 之后in发布到您的TextView中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM