简体   繁体   中英

How to run your java app using Sudo on MAC OS X

Today i need your help :x I've seen a lot of answer but there are never full.. I want to launch my java app by another with

Runtime.getRuntime().exec("my command");

On the MAC OS X. Then i found that command:

#!/bin/sh
osascript -e "do shell script \"$*\" with administrator privileges"

What have i to change in this script to run my app like on linux which is:

Runtime.getRuntime().exec("gksudo java -jar myjar");

I would like to have

Runtime.getRuntime().exec("osascript -e \"do shell script \\"$*\\" with administrator privileges");

but is it possible ? thanks for you anwser :/

Call the osascriptWrapper.sh script from Java:

Runtime.getRuntime().exec("/path/to/osascriptWrapper.sh myjar.jar");

Define osascriptWrapper.sh as:

#!/bin/bash

osascript -e "do shell script \"/path2/to2/runJar.sh $*\" with administrator privileges"

And runJar.sh:

#!/bin/bash

java -jar $*

您可以像在linux上一样在mac上使用sudo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM