繁体   English   中英

如何在Android中以编程方式执行终端命令

[英]How to execute terminal commands programmatically in android

在我的应用程序中,我想执行Linux终端命令,例如“ ls”,并在EditText中显示结果。

尝试这个

    try
    {
        Process process = Runtime.getRuntime().exec("ls");
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(process.getInputStream()));

        StringBuilder result = new StringBuilder();
        String line;
        while ((line = bufferedReader.readLine()) != null)
        {
            result.append(line + "\n");
        }
        EditText et = (EditText) findViewById(R.id.edittext);
        et.setText(result.toString());
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }

暂无
暂无

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

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