簡體   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