I am trying to execute a shell script from my Android application.
First I tried to run Shell script from Java ,and it working fine for all commands
like pwd
, cd
, netstat
. moving the file ,copying the file.
Than I've tried it from an Android application and I'm getting output for cd
,pwd
, netstat
and for echo statements that are in script, but for moving and copying the file are not working.
Are any Permissions needed to execute these commands from the script file while these commands are working fine from adb shell?
my code look like this:
void execCommandLine()
{
//***********************
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("ls -all");
proc = rt.exec("sh /data/shTest.sh");
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (Throwable t)
{
t.printStackTrace();
}
and my script file is as follows:
#!/bin/sh
echo "Knowledge is Power"
echo "I am a script"
echo $PATH
netstat
pwd
cd /data
pwd
cd /system/bin
pwd
mv /data/local/hello.txt /data/
cp /data/local/hello1.txt /data/
cd /data/local/tmp
cd /system/bin
Only the cp
and mv
commands are not showing expected result.
Please give me some guidance.
First thing I am trying and testing it into Emulator. In /system/bin have mv commond and I have also tried with busybox but I didnt get expected result. For root privilage how to proceed..Give some idea to proceed.