[Q] Parsing shell output from within Android app?

kschang

Senior Member
Dec 11, 2010
440
72
0
San Francisco, CA
Hi, I am an Android development newbie that has grasp of general concepts, played with ADB a little, and Eclipse a little.

My current idea is to develope an app that actually decodes the various memory stats for Android, merely as an education for my Android development. I do not intend to create "yet another task killer".

I know about free, meminfo, and procrank.

My overall objective are to run one of those (maybe all of them and somehow merge the numbers), get their numbers, parse them, and then display some sort of graph that will show where the memory went. Or in other words, I want to write something similar to DiskUsage, but for RAM.

So the question is... How do you run one of these shell (or busybox) commands, and get the output, so a Java program can parse it? My Google-fu is weak and I can't seem to find any references on this. though I think I am using the wrong keywords.

I know there's an app called Meminfo that displays cat /proc/meminfo so I know it can be done. Heck, SetCPU also does it (and much more under Info)
 

JimmyChingala

Senior Member
Apr 14, 2010
199
227
0
Melbourne
Hi, I am an Android development newbie that has grasp of general concepts, played with ADB a little, and Eclipse a little.

My current idea is to develope an app that actually decodes the various memory stats for Android, merely as an education for my Android development. I do not intend to create "yet another task killer".

I know about free, meminfo, and procrank.

My overall objective are to run one of those (maybe all of them and somehow merge the numbers), get their numbers, parse them, and then display some sort of graph that will show where the memory went. Or in other words, I want to write something similar to DiskUsage, but for RAM.

So the question is... How do you run one of these shell (or busybox) commands, and get the output, so a Java program can parse it? My Google-fu is weak and I can't seem to find any references on this. though I think I am using the wrong keywords.

I know there's an app called Meminfo that displays cat /proc/meminfo so I know it can be done. Heck, SetCPU also does it (and much more under Info)
For executing shell commands, look for code examples that use Runtime.getRuntime().exec(); like this post.

Depending on what you want to do, you may not need to execute shell commands to get this information: just open /proc/meminfo (or whateever) directly as a regular file and parse the content.

- jc
 
  • Like
Reactions: kschang