0

How can I run a linux command from an Android App and read the output. For example: retrieving output of "ls -lh" and printing as a text in TextView?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I get this error: java.io.IOException: Error running exec(). Command Working Directory: null Environment: null. Any idea whats this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.