问题
I am working on a project for builiding a shell for a java enabled mobile phone(using J2ME).I have to demonstarte 3 commands 1) ls 2) top 3)cat .How to implement them?Plese give me some ideas.Thanking you.
回答1:
Download Coreutils (it's the package which contains all of these commands): http://ftp.gnu.org/gnu/coreutils/coreutils-8.9.tar.gz.
Rip it open, and find the source code for each one. I think the tarball is organized quite nicely.
And some implementations of the commands in other languages (I like Python, as it's readable):
ls
: http://www.pixelbeat.org/talks/python/ls.py.html.cat
: http://www.unix.com/302420159-post2.html.top
is complicated. Good luck implementing it!
回答2:
You can use JSR 75 [File Connection API] to list out the files, which can be used to implement 'ls' command and using the same, you can implement the 'cat' command also.
However beware of the permissions, your app needs to be signed to be effective, otherwise for each subsequent requests to the file-system, the OS will be asking the user for permission, destroying the concept of a shell!
'top' can't be implemented in J2ME
Sample for File Connection API: File Sample
来源:https://stackoverflow.com/questions/5666514/command-shell-for-a-mobile-phone