Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void makeFifo(String path) throws Exception {
        execAsAdmin("mkfifo " + path);
        chmod(path, "666");
    }

    public static List<String> execAsAdmin(String... commands) throws Exception {
        List<String> res = new ArrayList<String>();

        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        for (String single : commands) {
            os.writeBytes(single + "\n");
            os.flush();
            //res.add(osRes.readLine());
        }
        os.writeBytes("exit\n");
        os.flush();
        //process.destroy();
        process.waitFor();

        return res;
    }

    public static void chmod(String path, String privileges) throws Exception {
        execAsAdmin("chmod " + privileges + " " + path);
    }
}