Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.DataOutputStream;

public class Main {
    /**
     * Run command as root.
     * 
     * @param command
     * @return true, if command was successfully executed
     */
    private static boolean runAsRoot(final String command) {
        try {

            Process pro = Runtime.getRuntime().exec("su");
            DataOutputStream outStr = new DataOutputStream(pro.getOutputStream());

            outStr.writeBytes(command);
            outStr.writeBytes("\nexit\n");
            outStr.flush();

            int retval = pro.waitFor();

            return (retval == 0);

        } catch (Exception e) {

            return false;

        }
    }
}