Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6220277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:55:48+00:00 2026-05-24T07:55:48+00:00

firstly I will present my situation. I need to execute su command in my

  • 0

firstly I will present my situation.
I need to execute “su” command in my android app and it works well. Then I need to execute “ls” command and read the output. I’m doing it by getting the output stream from the “su” process and writing my command into it.

And here goes the question. How to read the output of the “ls” process? All I have is the “su” Process object. Getting the input stream from it gives nothing, because “su” doesn’t write anything. But “ls” does and I don’t know how to access its output messages.

I have searched many sites but I didn’t find any solution. Maybe someone will help me:)

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:55:49+00:00Added an answer on May 24, 2026 at 7:55 am

    Ok, I’ve found a solution. It should look like this:

    Process p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"});
    DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
    //from here all commands are executed with su permissions
    stdin.writeBytes("ls /data\n"); // \n executes the command
    InputStream stdout = p.getInputStream();
    byte[] buffer = new byte[BUFF_LEN];
    int read;
    String out = new String();
    //read method will wait forever if there is nothing in the stream
    //so we need to read it in another way than while((read=stdout.read(buffer))>0)
    while(true){
        read = stdout.read(buffer);
        out += new String(buffer, 0, read);
        if(read<BUFF_LEN){
            //we have read everything
            break;
        }
    }
    //do something with the output
    

    Hope it will be helpful for someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will explain firstly what I do, then I will specify where is the
Please understand firstly that I fully understand that Java will return a String when
Firstly I will provide the structure of my branches Trunk Version1 (branch from trunk)
Firstly, I'm starting to use StructureMap, but an example in any DI framework will
Firstly, I'm using Django. Django provides gzip middleware which works just fine. Nginx also
Firstly, I'll explain the situation I'm in with my applicaton before I get onto
Firstly, I will say what I want to compare the following: My Custom Object
I have a work to do. Firstly, my program will be given an argument.
Firstly, is my logic about how much space this array will take up correct?
firstly, I apologize if my question sounds little confusing, I will try my best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.