Android Runtime.getRuntime (). Exec () for directory navigation

So, I want to write an application that can include and display logcat, dmesg messages, and also be able to run commands like 'ls' 'cat' 'echo' 'cd.'

If I do the following:

nativeProc = Runtime.getRuntime().exec("ls\n"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); String line = null; while ((line = in.readLine()) != null) { full = full + "\n" + line; } 

I can put the text "full" in the text view and see the root directory.

However, about all that I can do. Say I want to find a directory and change it, I have problems.

So, if I do this:

 nativeProc = Runtime.getRuntime().exec("ls\n"); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(nativeProc.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); String line = null; while ((line = in.readLine()) != null) { full = full + "\n" + line; } /* Code here to confirm the existing of a directory*/ nativeProc = Runtime.getRuntime().exec("cd tmp\n"); BufferedReader in2 = new BufferedReader(new InputStreamReader(nativeProc.getInputStream())); line = null; String test = "\nStart1:\n"; while ((line = in2.readLine()) != null) { test = test + "\n" + line; } 

I get nothing for "full" and "text"

Any ideas?

+6
android command-line terminal
source share
3 answers

You can execute ls with the provided path for which folders should be specified

 Runtime.getRuntime().exec(new String[] { "ls", "\\tmp"}); 
+4
source share

The current working directory is associated with the current process. When you execute ("cd tmp"), you create a process by changing its directory to "tmp" and then the process ends. The working directory of the parent process does not change.

See this for a more general discussion of changing the current working directory in Java .

+2
source share

How about writing a shell file that checks for the file and all other implementations in this file and adds it to the SD card and runs the shell file from java using getRuntimr.exec (), you can also pass parameters to it.

+1
source share

All Articles