Hire android application how to execute a shell script command
Guiqiu Great God pointing ~! In doing dishes a android application, you need to perform a system call command, and then I will consider written in .sh command script, direct the calling script execution. But the call has been unsuccessful. I specifically used the following line of function calls, system commands written in xxxxx.sh. Process proc = Runtime.getRuntime () exec ("/ system / bin / sh /system/bin/xxxxx.sh"); Please understand that under the guidance of friends, thank you! ! Reply: Come and help me ah Ding Dingding personal ~~~ Reply: Would you want the file permissions ah Reply:
I had permission to add this issue should not be set in the manifest file. Thank you for continuing to ask for help or to answer ah ~~~ Reply: This is a linux permissions, not the permissions manifest of android. You need to make sure ordinary linux user (android app) can execute your xxx.sh and can execute your script commands. Reply: This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } } Reply: You must first confirm whether the script script read-write privileges to note that the normal execution environment properly in adb.exe window If you can execute properly so
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; } Reply: Learn about Reply:
This code where you execute the shell script it? cmd or direct command execution, ah, what I need is a shell script execution, not resolved, continue to seek Reply: My shell script commands can be executed successfully in adb window. When invoked with android program, I set permissions in the manifest inside the system: android: sharedUserId = "android.uid.system", adb shell script file in the set chmod 777 permissions, Call script command: Process proc = Runtime.getRuntime () exec ("/ system / bin / sh /system/bin/xxxxx.sh"); .My approach and downstairs several said almost, but ultimately unsuccessful calls, continue to inquire what the problem is Reply: "My shell script commands can be executed successfully in adb window." You are root executed?
You first determine your sh script execution it? Or sh script command did not succeed?
exec ("/ system / bin / xxxxx.sh"); You can not Reply: Scripts have executable permissions Reply:
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice! Reply:
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true! Reply: If you can determine, in the manual execution * .sh is executable, then execShell ("./ xxx.sh"); also possible Reply:
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change. Reply:
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change.
1. You write this command is wrong, correct wording: busybox chmod 777 /data/data/com.XXX.XXX 2. If after a reboot, the permissions and changed back, then you have to re-execute the command, or if you modify init.xxx.rc file in the source code, so that he will not change with the restart Reply:
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change.
1. You write this command is wrong, correct wording: busybox chmod 777 /data/data/com.XXX.XXX 2. If after a reboot, the permissions and changed back, then you have to re-execute the command, or if you modify init.xxx.rc file in the source code, so that he will not change with the reboot
< / fieldset> In the CMD eyed chmod data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah.
Reply:
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change.
1. You write this command is wrong, correct wording: busybox chmod 777 /data/data/com.XXX.XXX 2. If after a reboot, the permissions and changed back, then you have to re-execute the command, or if you modify init.xxx.rc file in the source code, so that he will not change with the reboot
< / fieldset> In the CMD eyed chmod data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah.
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change.
1. You write this command is wrong, correct wording: busybox chmod 777 /data/data/com.XXX.XXX 2. If after a reboot, the permissions and changed back, then you have to re-execute the command, or if you modify init.xxx.rc file in the source code, so that he will not change with the reboot
< / fieldset> In the CMD eyed chmod data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah.
chmod ??? com.XXX.XXX ------ & gt; ??? represents the permissions
Sorry, I have that wrong, chmod 777 data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah. These two perform in code have not been successful, the preceding sentence at the command line is executed successfully, you say the phrase does not execute successfully! Reply:
This is a way to add to your application, you can, 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); // The command is written dataOutputStream.writeBytes (cmd); // Commit command dataOutputStream.flush (); // Close stream operations dataOutputStream.close (); outputStream.close (); } catch (Throwable t) { t.printStackTrace (); } }
I am using this did not succeed, I would like to ask you is how to achieve, there are some specific examples? Seek advice!
I wrote example is a button, click on the event is to call this method, the function of this method is to point the shell command, Meaning that you can put your documents in the * .sh command Through the implementation of a section of For example: execShell ("cd /"); execShell ("busybox touch xxx.txt"); Then you will find in the / directory xxx.txt file, the other copy, paste, and what command to query the same is true!
I would like to do something like this Code: Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Change file permissions, but this will not change.
1. You write this command is wrong, correct wording: busybox chmod 777 /data/data/com.XXX.XXX 2. If after a reboot, the permissions and changed back, then you have to re-execute the command, or if you modify init.xxx.rc file in the source code, so that he will not change with the reboot
< / fieldset> In the CMD eyed chmod data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah.
chmod ??? com.XXX.XXX ------ & gt; ??? represents the permissions
Sorry, I have that wrong, chmod 777 data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 /data/data/com.XXX.XXX not change ah. These two have not been successful in the implementation of the code, the first sentence in the successful implementation of the command line, you say the phrase does not execute successfully!
That should be inside your system does not use busybox tools, now do not entangled in this issue, engage in a now forgotten began to want to solve any problem! Reply: Problem solved? I have the same problem, there is the call cd / sdcard in android Lane / fail Reply: Nobody can return ah, I have failed, there are successful people look back. Reply: Shell on Android utilized to perform certain command has been packaged into a complete API, can be easily achieved, such as modifying hosts, copy files, install apk and perform certain actions with root privileges inferior, such as copies of the following documents:
String [] commands = new String [] {"mount -o rw, remount / system", "cp /mnt/sdcard/xx.apk / system / app /"}; CommandResult result = ShellUtils.execCommand (commands, true);
nobody can return ah, I have failed, there are successful people look back.
I now have this problem, cmd under chmod succeed, java code execution did not throw an exception, but did not change the file permissions.
Nobody has a ways?
Online permission to modify those methods, they are pit father of it?
There are wood succeeded ah Reply: Landlord you how to solve the final ah? Reply: The landlord, will solve the problem? Ability to share experiences, I also encountered the same problem, a bunch of commands can be executed properly in a command line, in code execution has not given but that did not take effect, the reason I do not know what ah Reply: I encountered this problem, but I used the C language to write applications, execute scripts.
But it does not seem to support the system ("ls -a"); exec ("");
No comments:
Post a Comment