RE:如何从我的Android应用程序执行shell脚本文件
我正在尝试编写一个android应用程序,运行一个shell命令,或者一个shell脚本(如果更好的话),并显示输出。。。有人能告诉我正确的方向吗 我的代码如下:RE:如何从我的Android应用程序执行shell脚本文件,android,shell,Android,Shell,我正在尝试编写一个android应用程序,运行一个shell命令,或者一个shell脚本(如果更好的话),并显示输出。。。有人能告诉我正确的方向吗 我的代码如下: void execCommandLine() { Runtime runtime = Runtime.getRuntime(); Process proc = null; OutputStreamWriter osw = null; try {
void execCommandLine()
{
Runtime runtime = Runtime.getRuntime();
Process proc = null;
OutputStreamWriter osw = null;
try
{
String[] str={"/system/bin/sh","/data/shTest.sh"};
System.out.println("EXEC STRING");
proc = runtime.exec(str);
osw = new OutputStreamWriter(proc.getOutputStream());
//osw.write(command);
osw.flush();
osw.close();
}
catch (IOException ex)
{
Log.e("erre","ioexception");
//Log.e("execCommandLine()", "Command resulted in an IO Exception: " + command);
return;
}
finally
{
if (osw != null)
{
try
{
osw.close();
}
catch (IOException e){}
}
}
try
{
proc.waitFor();
}
catch (InterruptedException e){}
if (proc.exitValue() != 0)
{
Log.e("erre","interruotexception");
//Log.e("execCommandLine()", "Command returned error: " + command + "\n Exit code: " + proc.exitValue());
}
}
// **************************************
代码正在成功运行,但我没有在adb shell logcat中获得任何输出
有人能告诉我这个脚本是否成功执行,如何获得这个输出吗
在Adb shell中。您是否查看了
GScript
。它相当灵活