简体   繁体   中英

How to install a .pkg from Java Runtime?

I am automating an installation of an .pkg file in Mac OS X using Java and to do it I have this command for bash console:

echo 'Control123' | sudo -S installer -pkg /Users/george/Downloads/MyPackage.pkg -target /

I am executing this command from Java Runtime:

Runtime.getRuntime().exec("echo 'Control123' | sudo -S installer -pkg /Users/george/Downloads/MyPackage.pkg -target /");

but the package is not installed, if execute the command in the Bash console. it works normally.

You shouldn't assume that a user has root privileges, and it's probably a better idea to launch the installer so the user can authorize and update the application from there. If that makes sense, then it's possible to launch the .pkg this way, sudo is not required:

String userHome = System.getProperty( "user.home" );
String cmdString = ("open " + userHome + "/Downloads/MyPackage.pkg");

I'm not sure why you would need echo 'Control123', but you might need to echo that separately.

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