Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RE:如何从我的Android应用程序执行shell脚本文件_Android_Shell - Fatal编程技术网

RE:如何从我的Android应用程序执行shell脚本文件

RE:如何从我的Android应用程序执行shell脚本文件,android,shell,Android,Shell,我正在尝试编写一个android应用程序,运行一个shell命令,或者一个shell脚本(如果更好的话),并显示输出。。。有人能告诉我正确的方向吗 我的代码如下: void execCommandLine() { Runtime runtime = Runtime.getRuntime(); Process proc = null; OutputStreamWriter osw = null; try {

我正在尝试编写一个android应用程序,运行一个shell命令,或者一个shell脚本(如果更好的话),并显示输出。。。有人能告诉我正确的方向吗

我的代码如下:

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
。它相当灵活