2013年7月26日星期五

Hire android application how to execute a shell script command

Knees and begged the god guidance ~!
dishes doing an android application that needs to execute the system call command, and then I consider in order to write. sh script, direct call script execution.
But the call has been unsuccessful.
I specifically used the following line of function calls, the system in order to write a xxxxx.sh
Process proc = Runtime.getRuntime (). exec ("/ system / bin / sh / system / bin / xxxxx.sh");
Please understand that friends pointing, thank you! !
------ Solution - -------------------------------------------
This is way to add to your application can be, relatively simple, huh!
public void execShell (String cmd) {
try {
/ / permissions
Process p = Runtime.getRuntime (). exec ("su"); ;
/ / Get the output stream
OutputStream outputStream = p.getOutputStream ();
DataOutputStream dataOutputStream = new DataOutputStream (outputStream);
/ / write the command
dataOutputStream.writeBytes (cmd);
/ / commit command
dataOutputStream.flush ();
/ / Close the stream operation
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}
------ Solution --------------------------- -----------------
first make sure your script is in the normal circumstances in adb.exe normal execution of the script window reads write permissions to note

So if executed correctly

... oncreate () {
test3 ()
}

private void test3 () {
execCommand1 ("system / bin / xxxx.sh");
}

public boolean execCommand1 (String cmd) {
Process process = null;
try {
process = Runtime.getRuntime (). exec (cmd);
process.waitFor ();
} catch (Exception e) {
return false;
} finally {
try {
process.destroy ();
} catch (Exception e) {
}
}
return true;
}
------ For reference only --------------------------------- ------
Come and help me personally Dingdingding ~ ~ ~
------ For reference only ---------------------------------------
will not have to file permissions
------ For reference only -------------------------------------- -

String command = "chmod 777" + path;
Runtime runtime = Runtime.getRuntime ();
runtime.exec (command);
------ For reference only --------------------------- ------------

I added a manifest file permissions set up should not be the problem. Thank you continue to ask for help or to answer ~ ~ ~
------ For reference This is the only ---------------------------------------
linux permissions are not android manifest permissions. You need to make sure ordinary linux user (android app) can execute your xxx.sh and can execute your script commands.
------ For reference only -------------------------------------- -
learn about
------ For reference only ---------------------------------------

you this code Where are executed in a shell script it? cmd or direct command execution, I need to execute a shell script, not resolved, continue to seek
------ For reference only ------------------ ---------------------
inside my shell script commands in the adb window can be successfully implemented.
with android program calls when I set up a system in the manifest inside permissions: android: sharedUserId = "android.uid.system",
shell script file in adb chmod 777 permissions in the set,
calling script command: Process proc = Runtime.getRuntime (). exec ("/ system / bin / sh / system / bin / xxxxx.sh");
my approach and downstairs several said almost, but ultimately unsuccessful call, inquired what the problem continues
------ For reference only ---------------------------------------
"inside my shell script adb command window can be successfully executed. "
you are root execution?


You make sure your sh script yet? Or sh script command did not succeed?

exec ("/ system / bin / xxxxx.sh");
not it can
------ For reference only ------------------------------- --------
scripts have executable permissions
------ For reference only ------------------- --------------------

I use this without success, I would like to ask you is how to achieve, there are some specific examples of it ? seeking advice!
------ For reference only ---------------------------------- -----

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!
------ For reference only -------------------------------------- -
you can determine if in manual execution *. sh is executable, then
execShell (". / xxx.sh"); also possible
------ For reference only -------------------- -------------------

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to shell commands
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.
------ For reference only -------------------------------------- -

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.

1. you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
2. If the device is restarted after the authority has changed back, then you have to re-execute the command, or if you modify init.xxx.rc files in the source code, so that he will not change with the reboot < br> ------ For reference only ---------------------------------------

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.

1. you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
2. If the device is restarted after the authority has changed back, then you have to re-execute the command, or if you modify init.xxx.rc files in the source code, so that he will not change with the reboot
inside the CMD with chmod data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed.

------ For reference only ---------------------------------- -----

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.

1. you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
2. If the device is restarted after the authority has changed back, then you have to re-execute the command, or if you modify init.xxx.rc files in the source code, so that he will not change with the reboot
inside the CMD with chmod data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed.

chmod??? com.XXX.XXX ------>??? represents the permissions
----- - For reference only ---------------------------------------

I use this without success, I would like to ask you is how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.

1. you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
2. If the device is restarted after the authority has changed back, then you have to re-execute the command, or if you modify init.xxx.rc files in the source code, so that he will not change with the reboot
inside the CMD with chmod data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed.

chmod??? com.XXX.XXX ------>??? represents the permissions

I'm sorry, I have that wrong, chmod 777 data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed. This two in the code execution without success, before a successful implementation of the command line, you say the phrase is not executed successfully!
------ For reference only --------- ------------------------------

I use this without success, I would like to ask you how to achieve, there are some specific examples? seeking advice!

I wrote example is a button, click on the event is to call this method, the function is a pointer to a shell command,
means that you can put your *. sh file command
one of the aspects of the implementation through the
example:
execShell ("cd /");
execShell ("busybox touch xxx.txt");
then you will be in the / directory to find a xxx.txt file, the other copy, paste, query what order the same is true!

I want to execute code like this:
Process p = Runtime.getRuntime (). exec ("chmod data / data / com.XXX.XXX"); changing file permissions, but that can not change.

1. you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
2. If the device is restarted after the authority has changed back, then you have to re-execute the command, or if you modify init.xxx.rc files in the source code, so that he will not change with the reboot
inside the CMD with chmod data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed.

chmod??? com.XXX.XXX ------>??? represents the permissions

I'm sorry, I have that wrong, chmod 777 data / data / com.XXX.XXX you can change permissions with what you say busybox chmod 777 / data / data / com.XXX.XXX can not be changed. This two in the code execution without success, before a successful implementation of the command line, you say the phrase is not executed successfully!
That should be inside your system does not use busybox tool, not now entangled in this issue, out of a now forgotten what started trying to solve the problem!

没有评论:

发表评论