Is there any graphical “sudo” for Mac OS X?

前端 未结 9 761
后悔当初
后悔当初 2020-12-05 07:44

I\'m designing a little software in Java. I don\'t know the term/definition to what I\'m doing, but I\'m prompting commands from Java to the terminal. Something like this:

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 08:02

    make the follows, in this example I go create a folder /var/lock and set your permissions to 777:

    String[] command = {
            "osascript",
            "-e",
            "do shell script \"mkdir -p /var/lock && chmod 777 /var/lock\" with administrator privileges" };
    Runtime runtime = Runtime.getRuntime();
    try {
        Process process = runtime.exec(command);
        BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = bufferedReader.readLine()) != null)
                System.out.println(line);
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    on linux maybe you can make this with gksudo but I not test it, after I go testing and post here the results.

提交回复
热议问题