chgrp, change group via shell command - Android Android OS

Android examples for Android OS:Shell Command

Description

chgrp, change group via shell command

Demo Code


import java.io.File;
import java.io.IOException;
import android.util.Log;

public class Main{
    public static int chgrp(File f, String gid) {
        String cmd = "chgrp " + gid + " " + f.getAbsolutePath();
        Log.i(Mocker.TAG, "Running command: " + cmd);
        return exec(cmd);
    }//  w  w  w  .  jav  a2s  .c om
    private static int exec(String cmd) {
        try {
            Runtime runtime = Runtime.getRuntime();
            Process p = runtime.exec(cmd);
            return p.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
            return -1;
        } catch (InterruptedException e) {
            e.printStackTrace();
            return -1;
        }
    }
}

Related Tutorials