Thursday, January 23, 2014

Hire android application how to execute a shell script command


            
Big knees and begged God pointing ~!
Doing dishes in an android application, you need to perform a system call command, and then I will consider writing a command. Sh script, direct the calling script execution.
But the call has been unsuccessful.
I specifically used the following line function call, the system commands written in
xxxxx.shProcess proc = Runtime.getRuntime () exec ("/ system / bin / sh / system / bin / xxxxx.sh");.
Please understand that friends pointing, thank you! !
Reply:
Come and help me ah Dingding personal ~ ~ ~
Reply:
Will not want to file permissions ah
Reply:

String command = "chmod 777" + path;
Runtime runtime = Runtime.getRuntime ();
runtime.exec (command);
Reply:
reference to the third 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 continue to ask for help or to answer ah ~ ~ ~
Reply:
This is a linux permissions, the permissions are not manifest in 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 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}
Reply:
You must first confirm whether
script in the script to read and write privileges to note that under normal normal execution environment adb.exe window
If you can run 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:
reference to the 6th floor f839903061 reply:
this is the 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
......

This code where you execute a shell script? cmd or direct command execution, ah, what I need is to execute a shell script, not resolved, continue to seek
Reply:
My shell script commands can be executed smoothly in the adb window.
When invoked with android, I set the permissions in the manifest inside the system: android: sharedUserId = "android.uid.system",
adb shell script file permissions in chmod 777 set,
Calling script command: Process proc = Runtime.getRuntime () exec ("/ system / bin / sh / system / bin / xxxxx.sh");
.My approach and downstairs several said almost, but eventually the call is unsuccessful, continue to inquire what the problem is
Reply:
"My shell script commands can be executed smoothly in the adb window."
You are root execution?


You make sure your sh script executes it? Sh script or command did not succeed?

exec ("/ system / bin / xxxxx.sh");
You can not
Reply:
Scripts have executable permissions
Reply:
reference to the 6th floor f839903061 reply:
this is the 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

I use this without success, I would like to ask you is how to achieve, there are some specific examples? Seeking advice!
Reply:
reference to the 13th floor qyqingyan reply:
Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 manually *. Sh executable, then
execShell ("/ xxx.sh."); also possible
Reply:
reference to the 14th floor f839903061 reply:
Quote: references to the 13th floor qyqingyan reply:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.
Reply:
reference to the 16th floor qyqingyan reply:
Quote: references to the 14th floor f839903061 reply:

Quote: Reply qyqingyan 13th floor of references:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.


1 you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
(2) If, after the device restarts, 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
Reply:
cited 17 floor f839903061 reply:
Quote: references to the 16th floor qyqingyan reply:

Quote: references to the 14th floor f839903061 reply:

Quote: Reply qyqingyan 13th floor of references:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.


1 you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
(2) If, after the device restarts, 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 inside with chmod data / data / com.XXX.XXX can change permissions ah, you said busybox chmod 777 / data / data / com.XXX.XXX not change ah.

Reply:
cited 18 floor qyqingyan reply:
Quote: references to 17th floor f839903061 reply:

Quote: 16th Floor reply qyqingyan of references:

Quote: references to the 14th floor f839903061 reply:

Quote: Reply qyqingyan 13th floor of references:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.


1 you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
(2) If, after the device restarts, 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 inside with 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 ------>??? represents the permissions
Reply:
cited 19th floor f839903061 reply:
Quote: 18th Floor qyqingyan cited reply:

Quote: references to 17th floor f839903061 reply:

Quote: 16th Floor reply qyqingyan of references:

Quote: references to the 14th floor f839903061 reply:

Quote: Reply qyqingyan 13th floor of references:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.


1 you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
(2) If, after the device restarts, 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 inside with 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 ------>??? represents the permissions


Sorry, I was wrong just that, 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 are not in the code execution is successful, the previous sentence successfully executed from the command line, you say the phrase does not run successfully!
Reply:
cited 20 floor qyqingyan reply:
Quote: 19th Floor f839903061 cited reply:

Quote: Reply qyqingyan 18th floor of references:

Quote: references to 17th floor f839903061 reply:

Quote: 16th Floor reply qyqingyan of references:

Quote: references to the 14th floor f839903061 reply:

Quote: Reply qyqingyan 13th floor of references:

Quote: references to the 6th floor f839903061 reply:

This is a 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 command
dataOutputStream.writeBytes (cmd);
/ / Commit command
dataOutputStream.flush ();
/ / Close the stream operations
dataOutputStream.close ();
outputStream.close ();
}
catch (Throwable t)
{
t.printStackTrace ();
}
}

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 of this method is that it points to a shell command,
Means that you can put your *. Sh file 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 want to execute code like this:
Process p = Runtime.getRuntime () exec ("chmod data / data / com.XXX.XXX");. Changing file permissions, but this can not be changed.


1 you write this command is wrong, the correct wording: busybox chmod 777 / data / data / com.XXX.XXX
(2) If, after the device restarts, 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 inside with 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 ------>??? represents the permissions


Sorry, I was wrong just that, 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 did not execute successfully!

That should be inside your system does not use busybox tools, not now entangled in this issue, do the now forgotten what started trying to solve the problem!
Reply:
Problem solved? I have the same problem, there is the call cd / sdcard in android Lane / fail
Reply:
Nobody reply ah, I have failed, there are successful people back to it.

No comments:

Post a Comment