Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.security.AccessController;

import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

public class Main {
    static void execPrivileged(final String[] cmd_array) throws Exception {
        try {
            Process process = AccessController.doPrivileged(new PrivilegedExceptionAction<Process>() {
                public Process run() throws Exception {
                    return Runtime.getRuntime().exec(cmd_array);
                }
            });
            // Close unused streams to make sure the child process won't hang
            process.getInputStream().close();
            process.getOutputStream().close();
            process.getErrorStream().close();
        } catch (PrivilegedActionException e) {
            throw (Exception) e.getCause();
        }
    }
}