【问题标题】:How to execute terminal commands programmatically in android如何在android中以编程方式执行终端命令
【发布时间】:2013-12-29 23:56:35
【问题描述】:

在我的应用程序中,我想执行 Linux-Terminal-Commands,例如“ls”和 在 EditText 中显示结果。

【问题讨论】:

    标签: android process terminal command runtime.exec


    【解决方案1】:

    试试这个

        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);
        }
    

    【讨论】:

    • 您能否将问题标记为已回答,以免将其显示为未回答? :)
    猜你喜欢
    • 2016-04-03
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多