Sunday, January 10, 2016

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:

String command = "chmod 777" + path;
Runtime runtime = Runtime.getRuntime ();
runtime.exec (command);
Reply:
quote 3rd floor gao000001 reply:
String command = "chmod 777" + path;
Runtime runtime = Runtime.getRuntime ();
runtime.exec (command);

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

... 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;
}
Reply:
Learn about
Reply:
quote, 6th Floor f839903061 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
......

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:
quote, 6th Floor f839903061 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!
Reply:
quote 13th floor qyqingyan reply:
Quote: quote, 6th Floor f839903061 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!
Reply:
If you can determine, in the manual execution * .sh is executable, then
execShell ("./ xxx.sh"); also possible
Reply:
quote the 14th floor f839903061 reply:
Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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:
quote 16th floor qyqingyan reply:
Quote: references to the 14th floor f839903061 reply:

Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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:
quote 17th floor f839903061 reply:
Quote: references to the 16th floor qyqingyan reply:

Quote: references to the 14th floor f839903061 reply:

Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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:
quote 18th floor qyqingyan reply:
Quote: quote 17th floor f839903061 reply:

Quote: references to the 16th floor qyqingyan reply:

Quote: references to the 14th floor f839903061 reply:

Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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; ??? shows permissions
Reply:
quote 19th floor f839903061 reply:
Quote: references to the 18th floor qyqingyan reply:

Quote: quote 17th floor f839903061 reply:

Quote: references to the 16th floor qyqingyan reply:

Quote: references to the 14th floor f839903061 reply:

Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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 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:
quote 20th floor qyqingyan reply:
Quote: references to the 19th floor f839903061 reply:

Quote: references to the 18th floor qyqingyan reply:

Quote: quote 17th floor f839903061 reply:

Quote: references to the 16th floor qyqingyan reply:

Quote: references to the 14th floor f839903061 reply:

Quote: quote 13th floor qyqingyan reply:

Quote: quote, 6th Floor f839903061 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);

Concrete can look at this article describes http: //www.trinea. cn / android / android-java-execute-shell-commands /
Reply:
quote the 23rd floor blacksilk reply:
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 ("");

Function interface

No comments:

Post a Comment