0

我正在尝试将 lighttpd 移植到 android,以便用户可以通过从浏览器中点击 localhost:port 从那里执行 php 脚本,但我的脚本无法正常工作

这是运行时java代码

公共类 RunTimeProvider { 布尔 isLoaded = false;

ProcessBuilder mysqlBuilder = new ProcessBuilder(new String[] {
        "/data/data/com.Punk.Qs/mysqld",
        "--defaults-file=/data/data/com.Punk.Qs/my.ini",
        "--user=root",
        "--language=/data/data/com.Punk.Qs/share/mysql/english" });

ProcessBuilder phpBuilder = new ProcessBuilder(new String[] {
        "/data/data/com.Punk.Qs/php-cgi-ext", "-c",
        "data/data/com.Punk.Qs/php.ini" });
ProcessBuilder lighttpdBuilder = new ProcessBuilder(new String[] {
        "/data/data/com.Punk.Qs/lighttpd", "-f",
        "data/data/com.Punk.Qs/lighttpd.conf" });

public void execute() {
    File fphp = new File("/data/data/com.Punk.Qs/php-cgi-ext");
    File flighttp = new File("/data/data/com.Punk.Qs/lighttpd");
    File fmysql = new File("/data/data/com.Punk.Qs/mysqld");
    if (fphp.exists() && flighttp.exists() && fmysql.exists()) {

        try {
            Runtime.getRuntime().exec(
                    "chmod 777 /data/data/com.Punk.Qs/lighttpd");
            lighttpdBuilder.start();

            //NativeApp(
                    "/data/data/com.Punk.Qs/lighttpd -f data/data/com.Punk.Qs/lighttpd.conf",
                    "lighttpd");

            Log.w("Lighttpd Started ", "Lighttpd successfully started");
        } catch (IOException e) {

            Log.w("Lighttpd Startup failed ", e);
            new ErrorLogger("Lighttpd", e.toString());
        }
        try {
            Runtime.getRuntime().exec(
                    "chmod 777 /data/data/com.Punk.Qs/mysqld");
            mysqlBuilder.start();
            //NativeApp(
                    "/data/data/com.Punk.Qs/mysqld --defaults-file=/data/data/com.Punk.Qs/my.ini --user=root --language=/data/data/com.Punk.Qs/share/mysql/english",
                    "mySQl");
            Log.d("mySQL Started ", "mySQL successfully started");
        } catch (IOException e) {
            Log.w("mySQL Startup failed ", e);
            new ErrorLogger("mySQl", e.toString());
        }
        try {
            Runtime.getRuntime().exec(
                    "chmod 777 /data/data/com.Punk.Qs/php-cgi-ext");
            phpBuilder.start();
            //NativeApp(
                    "/data/data/com.Punk.Qs/php-cgi-ext -c data/data/com.Punk.Qs/php.ini",
                    "phpCgi");

            Log.d("PHP Started ", "PHP successfully started");
        } catch (IOException e) {
            Log.w("PHP Startup failed ", e);
            new ErrorLogger("phpCgi", e.toString());

        }
    } else {
        Log.w("Error Runime Lib", "RunTime Libs is missing");

    }
    // return b;

}

public void NativeApp(String cmd, String tag) {

    Process nativeApp = null;

    Log.d("Executing :", cmd);
    try {

        nativeApp = Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
        Log.e("RunTime Error : ", e.toString());
        new ErrorLogger("RunTime", e.toString());
    }

    BufferedReader reader = new BufferedReader(new InputStreamReader(
            nativeApp.getInputStream()));
    int read;
    char[] buffer = new char[4096 * 8];
    StringBuffer output = new StringBuffer();
    try {

        while ((read = reader.read(buffer)) > 0) {
            output.append(buffer, 0, read);
        }

        reader.close();
    } catch (IOException e) {
        Log.e("IO Error : ", e.toString());
        new ErrorLogger("IO", e.toString());
    }

    // Waits for the command to finish.
    try {
        nativeApp.waitFor();
    } catch (InterruptedException e) {

        Log.e("InterruptedException : ", e.toString());
        new ErrorLogger("IntExp", e.toString());
    }

    String nativeOutput = output.toString();
    if (nativeOutput != null)
        isLoaded = true;
    Log.d("Output from : " + cmd, nativeOutput);
    new ErrorLogger("RunLib", nativeOutput);
}

}

方法 RunTimePRvider().execute()

当用户点击 Button 时将被调用

4

1 回答 1

1

做到这一点的最好方法是去一个开源项目并通过代码副本assets ,然后在你的设备或模拟器上检查它我也使用过这个项目来使用phplighthttpdandroid..

于 2013-08-23T12:43:40.033 回答