Android reading from InputStream not consistent
<p>I have a rooted android phone. I am trying to read the output of "ls" via my program:</p>

<pre><code>            Process p = null;
            p = Runtime.getRuntime().exec(new String[]{"su", "-c", "system/bin/sh"});
            DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
            stdin.writeBytes("ls / \n");
            stdin.flush();
            InputStream stdout = p.getInputStream();
</code></pre>

<p>and after that when I do read() , the read call blocks sometimes, sometimes it doesn't get blocked and I am able to read from the stream. Sometime i have to wait for the buffer to be filled.</p>

<pre><code>read = stdout.read(buffer);
</code></pre>

<p>Isn't there any consistent way in which this read could happen. I am doing ls on the same directory and i am noting different delays.</p>

<p>or</p>

<p>Is it better to use pseudo terminal?</p>
