exec shell script from android application

1,758 views
Skip to first unread message

jintao

unread,
Aug 7, 2010, 10:04:46 PM8/7/10
to android-ndk
Hi,

I need to execute some shell command, like "ls", in android java
application, and render the returned output of "ls" command in the
android java app.

Is this possible to get this done with JNI? Any guidance would be
greatly appreciated!

Thanks a lot!

jintao

Onur Cinar

unread,
Aug 9, 2010, 1:23:03 PM8/9/10
to andro...@googlegroups.com

Hi,

Since you will be doing the rendering in Java, you can avoid using JNI if you rely on the java.lang.Runtime's exec() methods:

http://developer.android.com/reference/java/lang/Runtime.html

When you do an exec() it will return a Process instance, and then you can access its output and input through getInputStream/getOutputStream.


The same is possible with POSIX popen() but it is not currently supported by bionic, so you can't use that in Android JNI. Instead you can probably use the system() and pipe the output to a file and then read that file afterwards.  Looks like the Java approach will be cleaner if you will be doing the rendering in Java.

Regards,

-onur





--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Tao Jin

unread,
Aug 9, 2010, 3:41:27 PM8/9/10
to andro...@googlegroups.com
Hi Onur,

Thanks tons! Really helpful!

br,

jintao

Reply all
Reply to author
Forward
0 new messages