1

I wanted to run some shell commands through a java program for android. The app just takes in a command executes it on the shell and returns the result.

I used this :

Process p=Runtime.getRuntime().exec(in); p.waitFor();

BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));

String line=reader.readLine();

output = line;

while(line!=null) {

   output = output +"\n"+ line;
   //System.out.println(line); 

line=reader.readLine();

}

"in" is the input from a text box.

1> I observed that most of the commands that come as a part of android work for the above statement. But i installed busybox to get other linux commands too. But none of these commands are running. Every time it just returns a NULL result. I Installed busybox both into /system/xbin as well as /system/bin (after remounting the /system partition as read/write)

2> Secondly if I do ls on a particular location like ls /sdcard, it takes /sdcard as the command. But ls -l works (just in case you feel the whitespace is causing a problem)

Please help me out

3
  • What is the content of in with a working command? What is the content of some busybox that does not work? Do you have some logcat of a non working exec? Commented Sep 23, 2012 at 11:48
  • For a non working exec - W/InputManagerService( 61): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406f2d28 Commented Sep 23, 2012 at 13:17
  • in" will get any command that is imput. for ex - if i input ls, in = "ls". This will execute. What do you mean by content of busybox? Commented Sep 23, 2012 at 13:18

1 Answer 1

0

The coding text input requires quotes in order to treat your input as one command, otherwise; each space is treated as a separate command on its own. Also, your output will only return the last buffer as 'line' where, it appears you were trying to set up an output variable 'output'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.