开发者

Android reading from InputStream not consistent

I have a rooted android phone. I am trying to read the output of "ls"开发者_开发知识库 via my program:

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

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.

read = stdout.read(buffer);

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.

or

Is it better to use pseudo terminal?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜